import GraphQLService from './GraphQLService';

export interface FloorPlanRoomTypeData{
  id? : number
  floorplan_id : string
  roomtype_id : string
  fr_floor_plan ?: {
    id : number
    number : number
    sqft : number
    title : string
  }
  fr_roomtype?: {
    id : number
    title : string
  }
}

export interface FloorPlanRoomTypeOPData {
  FloorPlanRoomTypeFind?: {
      rows?:FloorPlanRoomTypeData[]      
      total : number
      pages : number 
  };
}
export interface FloorPlanRoomTypeIdOPData {
  FloorPlanRoomTypeFindOneById?:FloorPlanRoomTypeData
}
export interface FloorPlanRoomTypeCreateOPData {
  FloorPlanRoomTypeCreate?:FloorPlanRoomTypeData
}

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 FloorPlanRoomTypeUpdateOPData {
  FloorPlanRoomTypeUpdate?:{
    snapshot: SnapshotData
    affected : number
    affectedRows ?: FloorPlanRoomTypeData
  }
}
export interface FloorPlanRoomTypeUpsertOPData {
  FloorPlanRoomTypeUpsert?:FloorPlanRoomTypeData
}
export interface FloorPlanRoomTypeDeleteOPData {
  FloorPlanRoomTypeDelete?:{
    snapshot: SnapshotData
    affected : number
  }
}

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

    getFloorPlanRoomType(pageSize:number, start:number):Promise<FloorPlanRoomTypeOPData |null | undefined>{
      const Query =`query Rows($filter: FloorPlanRoomTypeFindInput!) {
                    FloorPlanRoomTypeFind(filter: $filter) {
                      rows {
                        id
                        floorplan_id
                        roomtype_id
                        fr_floor_plan {
                          id
                          number
                          sqft
                          title
                        }
                        fr_roomtype {
                          id
                          title
                        }
                      }
                      total
                      pages
                    }
                  }`;
      const variables = {
          "filter": {
            "order": {
              "id": "DESC"
            },
            "skip": start,
            "take": pageSize
          }
      };
  
      return this.execute(Query, variables); 
    }

    getFloorPlanRoomTypeById(Id: number):Promise<FloorPlanRoomTypeIdOPData |null | undefined>{
      const Query =`query FloorPlanRoomTypeFindOneById($input: FloorPlanRoomTypeFindOneByIdInput!) {
                    FloorPlanRoomTypeFindOneById(input: $input) {
                      id
                      floorplan_id
                      roomtype_id
                      fr_floor_plan {
                        id
                        number
                        sqft
                        title
                      }
                      fr_roomtype {
                        id
                        title
                      }
                    }
                  }`;
        const variables = {
          "input": {
            "id": Id
          }
      };
  
      return this.execute(Query, variables); 
    }

    createFloorPlanRoomType(FloorPlanRoomTypeINData: FloorPlanRoomTypeData):Promise<FloorPlanRoomTypeCreateOPData |null | undefined>{
      const Query =`mutation FloorPlanRoomTypeCreate($input: [FloorPlanRoomTypeCreateInput!]!) {
                    FloorPlanRoomTypeCreate(input: $input) {
                      id
                      floorplan_id
                      roomtype_id
                      fr_floor_plan {
                        id
                        number
                        sqft
                        title
                      }
                      fr_roomtype {
                        id
                        title
                      }
                    }
                  }`;
      const variables = {
        input:[{
          "floorplan_id": parseInt(FloorPlanRoomTypeINData.floorplan_id),
          "roomtype_id": parseInt(FloorPlanRoomTypeINData.roomtype_id)
        }]
      };
  
      return this.mutate<FloorPlanRoomTypeCreateOPData>(Query, variables); 
    }

    updateFloorPlanRoomType(FloorPlanRoomTypeINData: FloorPlanRoomTypeData):Promise<FloorPlanRoomTypeUpdateOPData |null | undefined>{
      const Query =`mutation FloorPlanRoomTypeUpdate($input: FloorPlanRoomTypeUpdateInput!) {
                    FloorPlanRoomTypeUpdate(input: $input) {
                      snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                      affected
                      affectedRows {
                        id
                        floorplan_id
                        roomtype_id
                        fr_floor_plan {
                          id
                          title
                          number
                          sqft
                        }
                        fr_roomtype {
                          id
                          title
                        }
                      }
                    }
                  }`;
            const variables = {
              "input": {
                "sets": {
                  "floorplan_id": FloorPlanRoomTypeINData,
                  "roomtype_id": FloorPlanRoomTypeINData
                },
                "where": [
                  {
                    "id": {
                      "equal": null
                    }
                  }
                ]
              }
            };
  
      return this.mutate<FloorPlanRoomTypeUpdateOPData>(Query, variables); 
    }

    upsertFloorPlanRoomType(FloorPlanRoomTypeINData: FloorPlanRoomTypeData):Promise<FloorPlanRoomTypeUpsertOPData |null | undefined>{
      const Query =`mutation FloorPlanRoomTypeUpsert($input: [FloorPlanRoomTypeUpsertInput!]!) {
                    FloorPlanRoomTypeUpsert(input: $input) {
                      id
                      floorplan_id
                      roomtype_id
                      fr_floor_plan {
                        id
                        number
                        sqft
                        title
                      }
                      fr_roomtype {
                        id
                        title
                      }
                    }
                  }`;
            const variables = {
              input:[{
                "floorplan_id": null,
                "id": null,
                "roomtype_id": null
              }]
            };
  
      return this.mutate<FloorPlanRoomTypeUpsertOPData>(Query, variables); 
    }

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

    
}

const FloorPlanRoomTypeServiceInstance = new FloorPlanRoomTypeService();
export default FloorPlanRoomTypeServiceInstance;