const _PayUSdk = require('react-native').NativeModules.PayUSdk;

import requestParser from './utils/request';
import responseParser from './utils/response';

declare type PayUSdkSuccessBlock = (data: any) => void;
declare type PayUSdkErrorBlock = (data: any) => void;

class PayUSdk {

  constructor() {

  }

  makePayment(
    params: any,
    successBlock: PayUSdkSuccessBlock,
    errorBlock: PayUSdkErrorBlock
  ) {

    requestParser.SetRequestData(params);
    requestParser.ParseEsentials();
    params = requestParser.GetRequestData()

    _PayUSdk.makePayment(params, successBlock, errorBlock);
  }

  /*

  */
  async createPaymentRequest(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseEsentials();
    params = requestParser.GetRequestData()

    return await _PayUSdk.createPaymentRequest(params);
  }

  /*
  userCredentials
  */
  async fetchPaymentOptions(params: any) {

    requestParser.SetRequestData(params);

    params = requestParser.GetRequestData()

    const response =  await _PayUSdk.fetchPaymentOptions(params);
    return responseParser.ParsePaymentOptions(response);
  }

  /*

  */
  async vas(params: any) {

    requestParser.SetRequestData(params);

    params = requestParser.GetRequestData();
    const response =  await _PayUSdk.vas(params);
    return responseParser.ParseVAS(response);
  }

  /*
    cardNumber
  */
  async checkIsDomestic(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseCardNumber();

    params = requestParser.GetRequestData();

    const response =  await _PayUSdk.checkIsDomestic(params);
    return responseParser.ParseChecoIsDomastic(response);
  }

  /*
    CardNumber
    isSIInfo : boolean in a string 1 or 0
  */
  async getBinInfo(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseBinInfo();

    params = requestParser.GetRequestData();

    const response =  await _PayUSdk.getBinInfo(params);
    return responseParser.ParseBinInfo(response);
  }

  /*
    getConfig
  */
    async getConfig(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseGetConfig();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.getConfig(params);
      return responseParser.ParseGetConfig(response);
    }
  
  /*
    CheckBalance
  */
    async checkBalance(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseCheckBalance();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.checkBalance(params);
      return responseParser.ParseCheckBalance(response);
    }

  /*
    EligibleBins for Emi
  */
    async eligibleBinsForEmi(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseEligibleBinsForEmi();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.eligibleBinsForEmi(params);
      return responseParser.ParseEligibleBinsForEmi(response);
    }

  /*
    Delete tokenised user card
  */
    async deleteTokenisedCard(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseDeleteTokenisedUserCard();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.deleteTokenisedCard(params);
      return responseParser.ParseDeleteTokenisedUserCard(response);
    }

  /*
    Get tokenised user card
  */
    async getTokenisedCard(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseGetTokenisedCard();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.getTokenisedCard(params);
      return responseParser.ParseGetTokenisedCard(response);
    }

  /*
    Get tokenised user card details
  */
    async getTokenisedCardDetails(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseGetTokenisedCardDetails();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.getTokenisedCardDetails(params);
      return responseParser.ParseGetTokenisedCardDetails(response);
    }

  /*
    Get merchant ibibo codes
  */
    async getIbiboCodes(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseGetIbiboCodes();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.getIbiboCodes(params);
      return response;
    }

  /*
    Get merchant ibibo codes
  */
    async fetchIFSCDetails(params: any) {

      requestParser.SetRequestData(params);
      // requestParser.ParseFetchIFSCDetails();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.fetchIFSCDetails(params);
      return response;
    }

  /*
    Fetch Offer Details
  */
    async fetchOfferDetails(params: any) {

      requestParser.SetRequestData(params);
      //requestParser.ParseFetchOfferDetails();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.fetchOfferDetails(params);
      return response;
    }

  /*
    Validate Offer Details
  */
    async validateOfferDetails(params: any) {

      requestParser.SetRequestData(params);
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.validateOfferDetails(params);
      return response;
    }

    /*
    Validate Offer Details
  */
    async fetchAdsInformation(params: any) {

      requestParser.SetRequestData(params);
      //requestParser.ParseFetchAdsInformations();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.fetchAdsInformation(params);
      return response;
    }

    /*
    Validate Offer Details
  */
    async saveEventImpression(params: any) {

      requestParser.SetRequestData(params);
      //requestParser.ParseSaveEventImpression();
  
      params = requestParser.GetRequestData();
      
      const response =  await _PayUSdk.saveEventImpression(params);
      return response;
    }

  /*
    startTime
    endTime
  */
  async getTransactionInfo(params: any) {


    requestParser.SetRequestData(params);
    requestParser.ParseStartAndEndTime();

    params = requestParser.GetRequestData();

    const response = await _PayUSdk.getTransactionInfo(params);
    return responseParser.ParseTransectionInfo(response);
  }

  /*
    amount
  */
  async getEMIDetails(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseAmount();

    params = requestParser.GetRequestData();

    const response =  await _PayUSdk.getEMIDetails(params);

    return responseParser.ParseEmiDetails(response);
  }

  /*
    offerKey
    paymentType
    cardNumber
    ----
    var2
    var3: userCredentials
    var5: string Integer

  */
  async getCheckoutDetails(params: any) {



    return await _PayUSdk.getCheckoutDetails(params);
  }

  async verifyPayment(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseVerifyPayment();

    params = requestParser.GetRequestData();

    return await _PayUSdk.verifyPayment(params);

  }

  /*
    offerKey
    CardNumber
    amount
    var3: string('cash')
    var4: string('ppintent')
  */
  async getOfferStatus(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseOfferStatus();

    params = requestParser.GetRequestData();

    return await _PayUSdk.getOfferStatus(params);
  }

  async checkOfferDetails(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseCheckoutDetails();

    params = requestParser.GetRequestData();

    return await _PayUSdk.checkOfferDetails(params);
  }

  async getUserCards(params: any) {

    requestParser.SetRequestData(params);
    requestParser.ParseGetUserCard();

    params = requestParser.GetRequestData();

    return await _PayUSdk.getUserCards(params);
  }

  async saveUserCard(params: any) {
    requestParser.SetRequestData(params);
    requestParser.ParseSaveUserCard();

    params = requestParser.GetRequestData();
    return await _PayUSdk.saveUserCard(params);
  }

  async editUserCard(params: any) {
    requestParser.SetRequestData(params);
    requestParser.ParseEditUserCard();

    params = requestParser.GetRequestData();
    return await _PayUSdk.editUserCard(params);
  }

  async deleteStoredCard(params: any) {
    requestParser.SetRequestData(params);
    requestParser.ParseDeleteUserCard();

    params = requestParser.GetRequestData();
    return await _PayUSdk.deleteStoredCard(params);
  }

  async lookupAPI(params: any) {
    return await _PayUSdk.lookupAPI(params);
  }
}

export default new PayUSdk();
