// import Settle from "~/model/Public/Settle.js";
function buildData(model) {
    // this.settle = new Settle().data;
    this.model = model;
}

buildData.prototype.buildDoceot = function () {
    let doceots = [];
    let doceotList = this.model.trnmod.trndoc.doceot;
    for (let eot of doceotList) {
        let doceot = {};
        doceot.cortyp = eot.cortyp;
        doceot.docsnf = eot.docsnf;
        doceot.lev = eot.lev;
        doceot.rcv = this.buildPtspta(eot.rcv);
        doceots.push(doceot);
    }
    return doceots;
}
buildData.prototype.buildPtydet = function () {
    let ptydet = {};
    ptydet.rol = ptsptaObj.pts.rol;
    ptydet.dftfeecur = ptsptaObj.pts.dftfeecur;
    return ptydet;
}

buildData.prototype.buildPtspta = function () {
    let ptspta = {};
    let pts = ptsptaObj.pts;
    let adr = ptsptaObj.adr;
    ptspta.rol = pts.rol;
    ptspta.name = pts.nam;
    ptspta.ptyinr = pts.ptyinr;
    ptspta.ptainr = pts.ptainr;
    ptspta.extkey = pts.extkey;
    ptspta.dftdsp = pts.dftdsp;
    ptspta.dftcur = pts.dftcur;
    ptspta.dftact = pts.dftact;
    ptspta.dftfeecur = pts.dftfeecur;
    ptspta.dftactptainr = pts.dftactptainr;
    //ptspta.dftselrol=
    ptspta.glggrpflg = pts.glggrpflg;
    //ptspta.pansta=
    //ptspta.ptytyp=
    //ptspta.ptyextkey=
    ptspta.adrblk = pts.adrblk;
    //ptspta.rolsetflg=
    if (adr !== null && adr !== undefined) {
        ptspta.adrbic = adr.bic;
        ptspta.adrLoccty = adr.loccty;
    }
    return ptspta;

}

buildData.prototype.buildGlepan = function () {
    // let rec = {};
    let cbsMap = {};
    this.model.settle.rec.objtyp = "GID";
    this.model.settle.rec.ownref = this.model.gidgrp.rec.ownref;
    // this.model.settle.rec.objtyp = this.model.gidgrp.rec.objtyp;
    this.model.settle.rec.branchInr = this.model.gidgrp.rec.branchInr;
    this.model.settle.rec.detchgcod = this.model.gidgrp.rec.detchgcod;
    this.model.settle.rec.paytyp = this.model.gidgrp.rec.paytyp;
    this.model.settle.rec.swftyp = this.model.gidgrp.rec.swftyp;
    this.model.settle.rec.valdat = this.model.gidgrp.rec.valdat;
    this.model.settle.rec.gartyp = this.model.gidgrp.rec.gartyp;
    //  = rec;

    // cbsMap.NOM1 = {
    //     "cur": this.model.gidgrp.cbs.nom1.cur,
    //     "amt": this.model.gidgrp.cbs.nom1.amt,
    // }

    // cbsMap.OPN1 = {};

    // cbsMap.OPN2 = {
    //     "cur": this.model.gidgrp.cbs.opn2.cur,
    //     "amt": this.model.gidgrp.cbs.opn2.amt,
    // }

    // cbsMap.MAX = {
    //     "cur": this.model.gidgrp.cbs.max.cur,
    //     "amt": this.model.gidgrp.cbs.max.amt,
    // }

    // cbsMap.MAX2 = {
    //     "cur": this.model.gidgrp.cbs.max2.cur,
    //     "amt": this.model.gidgrp.cbs.max2.amt,
    // }

    Object.keys(this.model.gidgrp.cbs).forEach(key=>{
        cbsMap[key.toUpperCase()]= {...this.model.gidgrp.cbs[key]};
    })

    this.model.settle.cbsMap = cbsMap;

    let ptsptaList = [];
    let ptydetList = [];
    
    if (this.model.gidgrp.apl.pts.extkey !== "") {
        ptsptaList.push(this.model.gidgrp.apl.pts);
        // ptydetList.push(this.buildPtydet(this.model.gidgrp.apl));
    }
    if (this.model.gidgrp.adv.pts.extkey !== "") {
        ptsptaList.push(this.model.gidgrp.adv.pts);
        // ptydetList.push(this.buildPtydet(this.model.gidgrp.adv));
    }
    if (this.model.gidgrp.ben.pts.extkey !== "") {
        ptsptaList.push(this.model.gidgrp.ben.pts);
        // ptydetList.push(this.buildPtydet(this.model.gidgrp.ben));
    }
    this.model.settle.ptsList = ptsptaList;
    this.model.settle.ptydet = ptydetList;

    this.model.settle.setglg.setgll = [];
    this.model.settle.setfog.setfol = [];
    this.model.settle.setfeg.setfel = [];

    this.model.settle.doceotList = this.buildDoceot();
    //console.log(this.model);
    this.model.settle.transName = this.model.gidgrp.transName;
    // if (!!window.sessionStorage.userId) {
    //     this.model.settle.userId = window.sessionStorage.userId;
    // } else {
       
    // }
    this.model.settle.userId = "742549";

}

export default buildData;