import { sortOrder } from '@/constant/StaticData';
import GraphQLService from './GraphQLService';

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

export interface RoomTypeOPData {
  RoomTypeFind?:{
    rows?:RoomTypeData[],
    total:number,
    pages:number
  }
}
export interface RoomTypeIdOPData {
  RoomTypeFindOneById?:RoomTypeData
}
export interface RoomTypeCreateOPData {
  RoomTypeCreate?:RoomTypeData[]
}
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 RoomTypeUpdateOPData {
  RoomTypeUpdate?:{
    snapshot:SnapshotData 
    affected : number
    affectedRows?:RoomTypeData[]
  }
}
export interface RoomTypeUpsertOPData {
  RoomTypeUpsert?:RoomTypeData
}
export interface RoomTypeDeleteOPData {
  RoomTypeDelete?:{
    snapshot: SnapshotData
    affected : number
  }
}

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

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

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

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

    createRoomType(RoomTypeINData:RoomTypeData):Promise<RoomTypeCreateOPData |null | undefined>{
      const Query =`mutation RoomTypeCreate($input: [RoomTypeCreateInput!]!) {
                    RoomTypeCreate(input: $input) {
                      id
                      title
                      desc
                      
                    }
                  }`;
      const variables = {
        "input": [
          {
            "title": RoomTypeINData.title,
            "desc": RoomTypeINData.desc
          }
        ]
      };
  
      return this.mutate<RoomTypeCreateOPData>(Query, variables); 
    }

    updateRoomType(RoomTypeINData: RoomTypeData):Promise<RoomTypeUpdateOPData |null | undefined>{
      const Query =`mutation RoomTypeUpdate($input: RoomTypeUpdateInput!) {
                    RoomTypeUpdate(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": RoomTypeINData.title,
                  "desc": RoomTypeINData.desc
                },
                "where": [
                  {
                    "id": {
                      "equal": `${RoomTypeINData.id}`
                    }
                  }
                ]
              }
            };
  
      return this.mutate<RoomTypeUpdateOPData>(Query, variables); 
    }

    upsertRoomType(RoomTypeINData: RoomTypeData):Promise<RoomTypeUpsertOPData |null | undefined>{
      const Query =`mutation RoomTypeUpsert($input: [RoomTypeUpsertInput!]!) {
                      RoomTypeUpsert(input: $input) {
                        id
                        title
                        desc
                      }
                    }`;
            const variables = {
              "input": [
                {
                  "desc": null,
                  "id": null,
                  "title": null
                }
              ]
            };
  
      return this.mutate<RoomTypeUpsertOPData>(Query, variables); 
    }

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

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

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

const roomTypeServiceInstance = new RoomTypeService();
export default roomTypeServiceInstance;