import GraphQLService from './GraphQLService';

export interface personalInfo{
  id? : number
  fname : string
  lname : string 
}
export interface UserPersonalInfoCreateResponse {
  id: number;
  fname: string;
  lname: string;
}
export interface personalInfCreateOPData {
  UserPersonalInfoCreate?:UserPersonalInfoCreateResponse[]
}

export interface personalInfoData{
  id? : number
  fname : string
  lname : string 
}
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 personalInfUpdateOPData {
  UserPersonalInfoUpdate?:{
    snapshot: SnapshotData
    affected : number
    affectedRows ?: personalInfoData[]
  }
}

export interface personalInfDeleteOPData {
  UserPersonalInfoDelete?:{
    snapshot: SnapshotData
    affected : number
  }
}
class CustomerPersonalInfoService extends GraphQLService {
    constructor() {
      super();
    }

    createCustomerPersonalInfo(CustomerpersonalINData:personalInfo,singupID:number):Promise<personalInfCreateOPData |null | undefined>{
      const Query =`mutation UserPersonalInfoCreate($input: [UserPersonalInfoCreateInput!]!) {
                      UserPersonalInfoCreate(input: $input) {
                        id
                        fname
                        lname
                      }
                    }`;
      const variables = {
        input:[{
          "fname": CustomerpersonalINData.fname,
          "lname": CustomerpersonalINData.lname,
          "id": `${singupID}`
        }]
      };
  
      return this.mutate<personalInfCreateOPData>(Query, variables); 
    }

    updateCustomerPersonalInfo(personalInfINData: personalInfoData,userID:number):Promise<personalInfUpdateOPData |null | undefined>{
      const Query =`mutation UserPersonalInfoUpdate($input: UserPersonalInfoUpdateInput!) {
                    UserPersonalInfoUpdate(input: $input) {
                       snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                      affected
                      affectedRows {
                        id
                        fname
                        lname
                      }
                    }
                  }`;
            const variables = {
              "input": {
                "sets": {
                  "fname": personalInfINData.fname,
                  "lname": personalInfINData.lname
                },
                "where": [
                  {
                    "id": {
                      "equal": `${userID}`
                    }
                  }
                ]
              }
            };
  
      return this.mutate<personalInfUpdateOPData>(Query, variables); 
    }
    
    deleteCustomerPersonalInfo(Id: number):Promise<personalInfDeleteOPData |null | undefined>{
      const Query =`mutation UserPersonalInfoDelete($input: UserPersonalInfoDeleteInput!) {
                      UserPersonalInfoDelete(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<personalInfDeleteOPData>(Query, variables); 
    }
}

const CustomerPersonalInfoServiceInstance = new CustomerPersonalInfoService();
export default CustomerPersonalInfoServiceInstance;