//import Utils from '../../components/utils';
import Config from '../../config/appConstants';
import { sendAPI, getAPI, createAPIRequest } from "../api/endPoint";
// class WrapperService {

/* constructor() {

    this.loginDtls = store.getState().pki_details.hasOwnProperty("OrgUserValidator") ? store.getState().pki_details.OrgUserValidator : store.getState().pki_details;
} */

/*
@Param  - banUnique ID - integer
@Return - Bank Information for key
*/
export async function getBankInvolvedDetails(bankUniqueID) {
    return { bank: bankUniqueID };
}

/*
    @Param  - CRN,OwnerUniqueID - integer
    @Return - Applicant details
*/
export async function getInvolvedParty(params) {

    // var queryString = Object.keys(params).map(key => key + '=' + params[key]).join('&').replace(/\s/g, '%20');

    // //encodeURIComponent

    // let enc = btoa(Utils.bwEncryptHeaderAuthKey(queryString));




    let response = await getAPI(Config.GET_INVOVLED_PARTY, params);
    return response;
}

export async function getApplicantDetails(params) {
    let response = await getAPI(Config.REQUEST_RES_GETAPPLICATIOM, params);
    return response;
}

/* 
@desc - Get new RE Mark Details
*@params - REObjectID,REMarkID,TransactionID,ExternalReferenceNumber,KrookiNumber,ConcernedPartyID as Int
*/
export async function getREMarkData(params) {
    let resp = await getAPI(Config.GET_REMARK, params);
    return resp;
}

/* 
@desc - Get new RE Details (land details)
@params - KrookiNumber,VillageID,WilayatID,RegionID,ZoneID,OwnerUniqueID,REObjectID,REObjectStatusID as Int
*/
export async function getNewQueryREObject(params) {
    let resp = await createAPIRequest("GET", Config.GET_QUERY_RE_OBJECT, {}, params);
    return resp;
}

/* 
@desc - DynamicLookup for dropdown
@params - LookupType as Str
*/
export async function DynamicLookup() {
    let postData = {
        "LookupInput": [
            {
                "LookupType": "TransferType"
            }
        ]
    }
    let resp = await sendAPI('POST', Config.ET_UTILITY_LANDUSAGE_LOOKUP, postData);
    return resp;
}

/* 
@desc - getFees Lookup
@params - RegionID=1&FeeCodeID=901&ServiceSubID=RN13A&TxnAmount=500&SquareMeterArea=500 LookupType as Str
*/
export async function getFeesLookup(params) {
    let resp = await getAPI(Config.FEES_LOOKUP_URL, params);
    return resp;
    /*  var apiPath = Config.FEES_LOOKUP_URL + "?RegionID=" + getSelectedData.RegionID + "&FeeCodeID=" + Config.RN1_APPLICATION_REQUEST.FeeCodeID + "&ServiceSubID=" + getSelectedData.ServiceSubID;
         createRequestPayment('GET', apiPath, 1, "").then(
             (response) => {
                 this.setState({ fees_lookup: response.data });
                 this.responseData = response.data;
             }, (error) => {
                 console.log("_error  == " + error);
             }); */
}

// }
// export default WrapperService;

export async function GetLandInvolvedParty(params) {
    let resp = await getAPI(Config.GETLAND_INVOLVEDPARTYID + "/residential", params);
    return resp;
}


/*
    @Param  - Number
    @Return -  details
*/
export async function KrookiValidation(params) {
    let response = await createAPIRequest("GET", Config.KROOKI_VALIDATION, {}, params);
    return response;
}

export async function MunicipalityData(postData) {
    let resp = await createAPIRequest('POST', Config.POST_MUNICIPALITY, postData);
    return resp;
}

export async function ManPowerData(postData) {
    let resp = await createAPIRequest('POST', Config.POST_MANPOWER, postData);
    return resp;
}

export async function GetNewQueryREObject(params) {
    let resp = await getAPI(Config.GET_QUERY_RE_OBJECT, params);
    return resp;
}

export async function getLookUpList(lookUpName, template, formObjIndex, formInputIndex, idKeyName, englishKeyName, arabicKeyName, language, keyFields) {
    let inpuField = template.form[formObjIndex].formgroup.input[formInputIndex];
    inpuField.showAsterisk = true;
    inpuField.type = "select";
    inpuField.validator = {
        rules: [
            "required"
        ],
        errorMsg: [
            "PLS_CHOOSE_ANY_ONE_OPTION"
        ]
    }

    let postData = {
        "LookupInput": [
            {
                "LookupType": lookUpName
            }
        ]
    }

    if(keyFields){
        postData.LookupInput[0] = {
            ...postData.LookupInput[0],
            KeyFields: keyFields
        }
    }

    let response = await createAPIRequest("POST", Config.GET_UTILITY_LOOKUP, postData, {});
    if (response) {
        let lookUpFeilds = response.LookupDataFields;
        let list = [];
        lookUpFeilds.forEach((val, idx) => {
            list[idx] = { text: language === Config.LANG.AR ? lookUpFeilds[idx][arabicKeyName] : lookUpFeilds[idx][englishKeyName], value: lookUpFeilds[idx][idKeyName], selected: false };
        });
        inpuField.options = list;
        return {
            Template: template
        }
    } else {
        inpuField.options = [];
        return {
            Template: template
        }
    }
}

export async function GetRopDetails(params) {
    let response = await createAPIRequest("GET", Config.GET_ROP_PERSON_DETAILS, {}, params);
    if (response) {
        return response;
    } else {
        return false;
    }
}

export async function UpdateInvolvedParty(postData) {
let response = await createAPIRequest("PUT", Config.CREATE_INVOLVEPARTY, postData, {});
    if (response) {
        return response;
    }
}