import GraphQLService from './GraphQLService';

export interface FloorPlanFeaturesData{
  id?: number
  floorplan_id : string
  feature_id : string
  fr_floor_plan?: {
    id : number
    sqft : number
    title : string
    number : number
  }
  fr_feature ?: {
    id : number
    title : string
    desc : string
  }
}
export interface FloorPlanFeaturesOPData {
  FloorPlanFeaturesFind?: {
      rows?:FloorPlanFeaturesData[]      
      total : number
      pages : number 
  };
}
export interface FloorPlanFeaturesIdOPData {
  FloorPlanFeaturesFindOneById?:FloorPlanFeaturesData
}
export interface FloorPlanFeaturesCreateOPData {
  FloorPlanFeaturesCreate?:FloorPlanFeaturesData
}

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 FloorPlanFeaturesUpdateOPData {
  FloorPlanFeaturesUpdate?:{
    snapshot: SnapshotData
    affected : number
    affectedRows ?: FloorPlanFeaturesData
  }
}
export interface FloorPlanFeaturesUpsertOPData {
  FloorPlanFeaturesUpsert?:FloorPlanFeaturesData
}
export interface FloorPlanFeaturesDeleteOPData {
  FloorPlanFeaturesDelete?:{
    snapshot: SnapshotData
    affected : number
  }
}

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

    getFloorPlanFeatures(pageSize:number, start:number):Promise<FloorPlanFeaturesOPData |null | undefined>{
      const Query =`query Rows($filter: FloorPlanFeaturesFindInput!) {
                    FloorPlanFeaturesFind(filter: $filter) {
                      rows {
                        id
                        floorplan_id
                        feature_id
                        fr_floor_plan {
                          id
                          sqft
                          title
                          number
                        }
                        fr_feature {
                          id
                          title
                          desc
                        }
                      }
                      total
                      pages
                    }
                  }`;
      const variables = {
          "filter": {
            "order": {
              "id": "DESC"
            },
            "skip": start,
            "take": pageSize
          }
      };
  
      return this.execute(Query, variables); 
    }

    getFloorPlanFeaturesById(Id: number):Promise<FloorPlanFeaturesIdOPData |null | undefined>{
      const Query =`query FloorPlanFeaturesFindOneById($input: FloorPlanFeaturesFindOneByIdInput!) {
                    FloorPlanFeaturesFindOneById(input: $input) {
                      id
                      floorplan_id
                      feature_id
                      fr_floor_plan {
                        id
                        number
                        title
                        sqft
                      }
                      fr_feature {
                        id
                        title
                        desc
                      }
                    }
                  }`;
      const variables = {
          "input": {
            "id": Id
          }
      };
  
      return this.execute(Query, variables); 
    }

    createFloorPlanFeatures(FloorPlanFeaturesINData: FloorPlanFeaturesData):Promise<FloorPlanFeaturesCreateOPData |null | undefined>{
      const Query =`mutation FloorPlanFeaturesCreate($input: [FloorPlanFeaturesCreateInput!]!) {
                    FloorPlanFeaturesCreate(input: $input) {
                      id
                      floorplan_id
                      feature_id
                      fr_floor_plan {
                        id
                        number
                        sqft
                        title
                      }
                      fr_feature {
                        id
                        title
                        desc
                      }
                    }
                  }`;
      const variables = {
        input:[{
          "feature_id": parseInt(FloorPlanFeaturesINData.feature_id),
          "floorplan_id": parseInt(FloorPlanFeaturesINData.floorplan_id)
        }]
      };
  
      return this.mutate<FloorPlanFeaturesCreateOPData>(Query, variables); 
    }

    updateFloorPlanFeatures(FloorPlanFeaturesINData: FloorPlanFeaturesData):Promise<FloorPlanFeaturesUpdateOPData |null | undefined>{
      const Query =`mutation FloorPlanFeaturesUpdate($input: FloorPlanFeaturesUpdateInput!) {
                    FloorPlanFeaturesUpdate(input: $input) {
                      snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                      affected
                      affectedRows {
                        id
                        floorplan_id
                        feature_id
                        fr_floor_plan {
                          id
                          number
                          sqft
                          title
                        }
                        fr_feature {
                          id
                          title
                          desc
                        }
                      }
                    }
                  }`;
            const variables = {
              "input": {
                "sets": {
                  "feature_id": null,
                  "floorplan_id": null
                },
                "where": [
                  {
                    "id": {
                      "equal": null
                    }
                  }
                ]
              }
            }; 
  
      return this.mutate<FloorPlanFeaturesUpdateOPData>(Query, variables); 
    }

    upsertFloorPlanFeatures(FloorPlanFeaturesINData: FloorPlanFeaturesData):Promise<FloorPlanFeaturesUpsertOPData |null | undefined>{
      const Query =`mutation FloorPlanFeaturesUpsert($input: [FloorPlanFeaturesUpsertInput!]!) {
                    FloorPlanFeaturesUpsert(input: $input) {
                      id
                      floorplan_id
                      feature_id
                      fr_floor_plan {
                        id
                        number
                        sqft
                        title
                      }
                      fr_feature {
                        id
                        title
                        desc
                      }
                    }
                  }`;
            const variables = {
              input:[
                {
                  "feature_id": null,
                  "floorplan_id": null,
                  "id": null
                }
              ]
            };
  
      return this.mutate<FloorPlanFeaturesUpsertOPData>(Query, variables); 
    }

    deleteFloorPlanFeatures(Id: number):Promise<FloorPlanFeaturesDeleteOPData |null | undefined>{
      const Query =`mutation FloorPlanFeaturesDelete($input: FloorPlanFeaturesDeleteInput!) {
                      FloorPlanFeaturesDelete(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<FloorPlanFeaturesDeleteOPData>(Query, variables); 
    }
}

const FloorPlanFeaturesServiceInstance = new FloorPlanFeaturesService();
export default FloorPlanFeaturesServiceInstance;