import GraphQLService from './GraphQLService';

export interface ArchitectureStyleData{
  id : number
  title : string
  desc : string 
}

export interface ArchitectureStyleOPData {
  ArchitectureStyleFind?: {
        rows?:ArchitectureStyleData[]
        pages : number        
        total : number
    };
}

export interface ArchitectureStyleIdOPData {
  ArchitectureStyleFindOneById?:ArchitectureStyleData
}

export interface ArchitectureStyleCreateOPData {
  ArchitectureStyleCreate?:ArchitectureStyleData[]
}

export interface ArchitectureStyleUpdateOPData {
  ArchitectureStyleUpdate?:{
    snapshot: SnapshotData
    affected : number
    affectedRows ?:ArchitectureStyleData[]
  }
}

export interface ArchitectureStyleUpsertOPData {
  ArchitectureStyleUpsert?:ArchitectureStyleData[]
}

interface SnapshotData {
  message : string
  result : string
  imp : string
  mismatch : string
  notFound : string
  conflict : string
  success : string
  error : string
  alert : string
  warning : string
  notice : string
  info : string
}
export interface ArchitectureStyleDeleteOPData {
  ArchitectureStyleDelete?:{
    snapshot: SnapshotData
    affected : number
  }
}

class ArchitectureStyleService extends GraphQLService {
    constructor() {
      super();
    }

    getArchitectureStyle(pageSize:number, start:number,sortorder:string):Promise<ArchitectureStyleOPData |null | undefined>{
      const Query =`query Rows($filter: ArchitectureStyleFindInput!) {
                    ArchitectureStyleFind(filter: $filter) {
                      rows {
                        id
                        title
                        desc
                      }
                      pages
                      total
                    }
                  }`;
      const variables = {
          "filter": {
            "order": {
            "title":sortorder
            },
            "skip": start,
            "take": pageSize
          }
      };
  
      return this.execute(Query, variables); 
    }

    getAllArchitectureStyle():Promise<ArchitectureStyleOPData |null | undefined>{
      const Query =`query Rows($filter: ArchitectureStyleFindInput!) {
                    ArchitectureStyleFind(filter: $filter) {
                      rows {
                        id
                        title
                        desc
                      }
                      pages
                      total
                    }
                  }`;
      const variables = {
          "filter": {
            "order": {
            "id": "DESC"
            },
            
          }
      };
  
      return this.execute(Query, variables); 
    }

    getArchitectureStyleById(Id: number):Promise<ArchitectureStyleIdOPData |null | undefined>{
      const Query =`query ArchitectureStyleFindOneById($input: ArchitectureStyleFindOneByIdInput!) {
                    ArchitectureStyleFindOneById(input: $input) {
                      id
                      title
                      desc
                    }
                  }`;
      const variables = {
          "input": {
            "id": Id
          }
      };
  
      return this.execute(Query, variables); 
    }

    createArchitectureStyle(ArchitectureStyleINData: ArchitectureStyleData):Promise<ArchitectureStyleCreateOPData |null | undefined>{
      const Query =`mutation ArchitectureStyleCreate($input: [ArchitectureStyleCreateInput!]!) {
                    ArchitectureStyleCreate(input: $input) {
                      id
                      title
                      desc
                    }
                  }`;
      const variables = {
        input:[ArchitectureStyleINData]
      };
  
      return this.mutate<ArchitectureStyleCreateOPData>(Query, variables); 
    }

    updateArchitectureStyle(ArchitectureStyleINData: ArchitectureStyleData):Promise<ArchitectureStyleUpdateOPData |null | undefined>{
      const Query =`mutation ArchitectureStyleUpdate($input: ArchitectureStyleUpdateInput!) {
                    ArchitectureStyleUpdate(input: $input) {
                      snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                      affected
                      affectedRows {
                        id
                        title
                        desc
                      }
                    }
                  }`;
            const variables = {
              "input": {
                "sets": {
                          "title": ArchitectureStyleINData.title,
                          "desc": ArchitectureStyleINData.desc,
                        },
                "where" :  [{
                    "id": {
                      "equal": `${ArchitectureStyleINData.id}`
                    }
                  }]
              }
            };
  
      return this.mutate<ArchitectureStyleUpdateOPData>(Query, variables); 
    }

    upsertArchitectureStyle(ArchitectureStyleINData: ArchitectureStyleData):Promise<ArchitectureStyleUpsertOPData |null | undefined>{
      const Query =`mutation ArchitectureStyleUpsert($input: [ArchitectureStyleUpsertInput!]!) {
                    ArchitectureStyleUpsert(input: $input) {
                      id
                      title
                      desc
                    }
                  }`;
            const variables = {
              input:[ArchitectureStyleINData]
            };
  
      return this.mutate<ArchitectureStyleUpsertOPData>(Query, variables); 
    }

    deleteArchitectureStyle(Id: number):Promise<ArchitectureStyleDeleteOPData |null | undefined>{
      const Query =`mutation ArchitectureStyleDelete($input: ArchitectureStyleDeleteInput!) {
                    ArchitectureStyleDelete(input: $input) {
                      affected
                      snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                    }
                  }`;
            const variables = {
              input:{
                "where": [
                  {
                    "id": {
                      "equal": `${Id}`
                    }
                  }
                ]
              }
            };
  
      return this.mutate<ArchitectureStyleDeleteOPData>(Query, variables); 
    }

    sortAscGetArchitectureStyle(sortOrder:string,pageSize:number, start:number):Promise<ArchitectureStyleOPData |null | undefined>{
      const Query =`query Rows($filter: ArchitectureStyleFindInput!) {
                    ArchitectureStyleFind(filter: $filter) {
                      rows {
                        id
                        title
                        desc
                      }
                      pages
                      total
                    }
                  }`;
      const variables = {
        "filter": {
          "order": {
            "title": sortOrder
          },
          "skip": start,
          "take": pageSize
        }
    };

      return this.execute(Query, variables); 
    }
}

const archiStyleServiceInstance = new ArchitectureStyleService();
export default archiStyleServiceInstance;