import GraphQLService from './GraphQLService';

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
}

interface OtpTypeData {
  snapshot: SnapshotData;
  id: number;
  otp: string;
  otp_expiry: string;
  primary_email:string
}

interface OtpCreateOPData {
    AppOtpSignin: OtpTypeData;

}

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

    createOtpSignin(OtpINData:OtpTypeData):Promise<OtpCreateOPData |null | undefined>{
      const Query =`mutation AppOtpSignin($input: AppOtpSigninInput!) {
                    AppOtpSignin(input: $input) {
                      id
                      otp
                      otp_expiry
                      snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                    }
                  }`;
      const variables = {
        "input": {
        
            "un_pe_pm": `${OtpINData.primary_email}`
         
        }
      };
  
      return this.mutate<OtpCreateOPData>(Query, variables); 
    }

    createOtpSigninFromButtonClick(OtpINData:OtpTypeData):Promise<OtpCreateOPData |null | undefined>{
      const Query =`mutation AppOtpSignin($input: AppOtpSigninInput!) {
                    AppOtpSignin(input: $input) {
                      id
                      otp
                      otp_expiry
                      snapshot {
                        message
                        result
                        imp
                        mismatch
                        notFound
                        conflict
                        success
                        error
                        alert
                        warning
                        notice
                        info
                      }
                    }
                  }`;
      const variables = {
        "input": {
        
            "un_pe_pm": `${OtpINData}`
         
        }
      };
  
      return this.mutate<OtpCreateOPData>(Query, variables); 
    }
}

const UserOtpServiceInstance = new UserOtpService();
export default UserOtpServiceInstance;