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

import com.brilliance.isc.bo.Cci;
import com.brilliance.isc.bo.Pts;
import com.brilliance.isc.common.register.cci.CliBanInfo;
import com.brilliance.isc.common.vo.PtsptaVo;
import com.brilliance.isc.mda.dao.PtsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Component("DFD.cciRegister")
public class DfdCliBanInfo implements CliBanInfo {

    @Autowired
    private PtsMapper ptsMapper;

    @Override
    public void buildValue(String objinr, String objtyp, List<PtsptaVo> ptsptaVos, Cci cci) {
        //getDFdCliBanInfo
        List<Pts> ptsList = ptsMapper.getPtsByObjInrTyp(objinr, objtyp);
        if (ptsList == null || ptsList.size() == 0) {
            ptsList = new ArrayList<>();
            for (PtsptaVo ptsptaVo : ptsptaVos) {
                ptsList.add(ptsptaVo.getPts());
            }
        }
        if (ptsList == null || ptsList.size() == 0) {
            return;
        }
        cci.setCcicusrol("APL");
        Optional<Pts> optionalPts = ptsList.stream().filter(pts -> cci.getCcicusrol().equalsIgnoreCase(pts.getRol())).findFirst();
        if (optionalPts.isPresent()) {
            cci.setCcicusptainr(optionalPts.get().getPtainr());
        }
        cci.setCcibanrol("");
        optionalPts = ptsList.stream().filter(pts -> cci.getCcibanrol().equalsIgnoreCase(pts.getRol())).findFirst();
        if (optionalPts.isPresent()) {
            cci.setCcibanptainr(optionalPts.get().getPtainr());
        }
    }
}
