package com.brilliance.isc.common.register.dftcre.impl;

import com.brilliance.isc.bo.Cbb;
import com.brilliance.isc.bo.model.Dftcre;
import com.brilliance.isc.common.component.PtsptaToolComponent;
import com.brilliance.isc.common.register.dftcre.IDftcreRegister;
import com.brilliance.isc.vo.model.DftcreBizInfoVo;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("bed.dftcreRegister")
public class BedDftcreRegister implements IDftcreRegister {

    @Autowired
    private PtsptaToolComponent ptsptaToolComponent;

    @Override
    public void setDFDfieldsfromXXX(Dftcre dftcreVo) {
        DftcreBizInfoVo rec = dftcreVo.getRec();
        dftcreVo.getDfdgrp().getRec().setPntinr(rec.getObjinr());
        dftcreVo.getDfdgrp().getRec().setPnttyp(rec.getObjtyp());
        dftcreVo.getDfdgrp().getRec().setPntnam(rec.getNam());
        dftcreVo.getDfdgrp().getRec().setPntref(rec.getOwnref());
        Cbb opnCbb = dftcreVo.getCbsMap().getOrDefault("OPN1", new Cbb());
        dftcreVo.getDfdgrp().getCbs().getMax().setCur(opnCbb.getCur());
        String ref = dftcreVo.getDfdgrp().getApl().getRef();
        if (ptsptaToolComponent.ptsIsRolSet(dftcreVo.getPtsptaList(), "BEN")) {
            dftcreVo.getDfdgrp().setApl(MdaUtils.deepClone(ptsptaToolComponent.getPtsFromListByRol(dftcreVo.getPtsptaList(), "BEN")));
        }
        dftcreVo.getDfdgrp().getApl().setRol("APL");
        dftcreVo.getDfdgrp().getApl().getPts().setRol("APL");
        if (StringUtils.isNotEmpty(ref)) {
            dftcreVo.getDfdgrp().getApl().getPts().setRef(ref);
        }
    }
}
