package com.brilliance.isc.common.transaction.check;

import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.util.I18nUtil;
import com.brilliance.isc.common.util.StringUtils;
import com.brilliance.isc.common.vo.CnybopVo;
import com.brilliance.isc.common.vo.CnyvouVo;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.apache.commons.collections4.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@Component
public class CnybopCheck implements ICheck<CnybopVo> {

    public Map<String, String> check(CnybopVo vo) {
        Map<String, String> maps = new HashMap<>();
        maps.putAll(checkCnyvouSvouchercountrycodeN1000(vo));
        maps.putAll(checkCnyvouSvoucheecountrycodeN1000(vo));
        maps.putAll(checkCnyvouSdebtorcountrycodeN1000(vo));
        maps.putAll(checkCnyflgN1000(vo));
        maps.putAll(checkTraflgN1000(vo));
        maps.putAll(checkOutflgN1000(vo));
        maps.putAll(checkLibflgN1000(vo));
        maps.putAll(checkVouflgN1000(vo));
        maps.putAll(checkCnyvouSbankorgcodeN1000(vo));
        maps.putAll(checkSbanknameN1000(vo));
        maps.putAll(checkCnyvouScontractnoN1000(vo));
        maps.putAll(checkCnyvouCurrencycodeN1000(vo));
        maps.putAll(checkCnyvouDvouchefficientdateN1000(vo));
        maps.putAll(checkCnyvouDvouchenddateN1000(vo));
        maps.putAll(checkSaddwordvouN1000(vo));
        maps.putAll(checkCnyvouStransattrN1000(vo));
        maps.putAll(checkSvouchernameN1000(vo));
        maps.putAll(checkCnyvouCvouchdirectionN1000(vo));
        maps.putAll(checkSvoucheenameN1000(vo));
        maps.putAll(checkSdebtornameN1000(vo));
        maps.putAll(checkCnyvouCvouchtypeN1000(vo));
        maps.putAll(checkCnyvouFvouchamtN1000(vo));

        return maps;
    }

    public Map<String, String> checkCnyvouSvouchercountrycodeN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getSvouchercountrycode())) {
                // Platform.errorMandatory();
                map.put("cnybop.cnyvou.svouchercountrycode", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    
    public Map<String, String> checkCnyvouSvoucheecountrycodeN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getSvoucheecountrycode())) {
                // Platform.errorMandatory();
                map.put("cnybop.cnyvou.svouchercountrycode", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    
    public Map<String, String> checkCnyvouSdebtorcountrycodeN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getSdebtorcountrycode())) {
                // Platform.errorMandatory();
                map.put("cnybop.cnyvou.sdebtorcountrycode", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    
    public Map<String, String> checkCnyflgN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        switch (SettleContext.getTransName()) {
            case "CPTADV":
                if (MdaUtils.isEmpty(cnybopVo.getCnyflg())) {
                    //  Platform.errorMandatory();
                    map.put("cnybop.cnyflg", I18nUtil.getMessage("0002"));
                } else {
                    if (MdaUtils.compareTo(cnybopVo.getCnyflg(), "1") == 0 && MdaUtils.compareTo(cnybopVo.getTraflg(), "1") == 0) {
                        // ctx.setFieldError(this,"cnyflg",MdaUtils.getI18NString("cnybop","CT000057"));
                        map.put("cnybop.cnyflg", I18nUtil.getMessage("0052"));
                    }
                }
                break;
            case "BOTSET":
            case "BETSET":
            case "GETSET":
            case "BTTSET":
            case "CCTSET":
            case "CPTREP":
                if (MdaUtils.isEmpty(cnybopVo.getCnyflg())) {
                    //  Platform.errorMandatory();
                    map.put("cnybop.cnyflg", I18nUtil.getMessage("0002"));
                }
                break;
        }
        return map;
    }

    
    public Map<String, String> checkTraflgN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        switch (SettleContext.getTransName()) {
            case "CPTADV":
                if (MdaUtils.isEmpty(cnybopVo.getTraflg())) {
                    // Platform.errorMandatory();
                    map.put("cnybop.traflg", I18nUtil.getMessage("0002"));
                } else {
                    if (MdaUtils.compareTo(cnybopVo.getTraflg(), "1") == 0) {
                        //  ctx.setFieldError(this,"traflg",MdaUtils.getI18NString("cnybop","CT000051"));
                        map.put("cnybop.traflg", MdaUtils.getI18NString("cnybop", "CT000051"));
                    }
                }
                break;
            case "CPTOPN":
            case "CPTREP":
                if (MdaUtils.isEmpty(cnybopVo.getTraflg())) {
                    // Platform.errorMandatory();
                    map.put("cnybop.traflg", I18nUtil.getMessage("0002"));
                } else {
                    if (MdaUtils.compareTo(cnybopVo.getOutflg(), "1") == 0 && MdaUtils.compareTo(cnybopVo.getTraflg(), "1") == 0) {
                        // ctx.setFieldError(this,"traflg",MdaUtils.getI18NString("cnybop","CT000052"));
                        map.put("cnybop.traflg", I18nUtil.getMessage("0053"));
                    }
                    if (MdaUtils.compareTo(cnybopVo.getCnyflg(), "1") == 0 && MdaUtils.compareTo(cnybopVo.getTraflg(), "1") == 0) {
                        //  ctx.setFieldError(this,"traflg",MdaUtils.getI18NString("cnybop","CT000056"));
                        map.put("cnybop.traflg", I18nUtil.getMessage("0052"));
                    }
                }
                break;
        }
        return map;
    }

    
    public Map<String, String> checkOutflgN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        switch (SettleContext.getDirectTransName()) {
            case "CPTOPN":
            case "BRTSET":
            case "BCTSET":
            case "GITSET":
                if (MdaUtils.isEmpty(cnybopVo.getOutflg())) {
                    //  Platform.errorMandatory();
                    map.put("cnybop.outflg", I18nUtil.getMessage("0002"));
                } else {
                    if (MdaUtils.compareTo(cnybopVo.getOutflg(), "1") == 0 && MdaUtils.compareTo(cnybopVo.getTraflg(), "1") == 0) {
                        // ctx.setFieldError(this,"outflg",MdaUtils.getI18NString("cnybop","CT000054"));
                        map.put("cnybop.outflg", I18nUtil.getMessage("0053"));
                    }
                }
                break;
        }
        return map;
    }

    
    public Map<String, String> checkLibflgN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        switch (SettleContext.getTransName()) {
            case "LITOPN":
            case "LTTOPN":
            case "BCTDAV":
            case "BETSND":
            case "BOTDAV":
            case "BTTSND":
                if (MdaUtils.isEmpty(cnybopVo.getLibflg())) {
                    // Platform.errorMandatory();
                    map.put("cnybop.libflg", I18nUtil.getMessage("0002"));
                }
                break;
        }
        return map;
    }

    
    public Map<String, String> checkVouflgN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        String frm = SettleContext.getUserSession().getAtp().getCod();
        switch (frm) {
            case "GITOPN":
            case "GITODZ":
                /*
                 case "GITOPN"
                 */
                if (MdaUtils.isEmpty(cnybopVo.getVouflg())) {
                    //Platform.errorMandatory();
                    map.put("cnybop.vouflg", I18nUtil.getMessage("0002"));
                }
                break;
        }
        return map;
    }

    
    public Map<String, String> checkCnyvouSbankorgcodeN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getSbankorgcode())) {
                // Platform.errorMandatory();
                map.put("cnybop.cnyvou.sbankorgcode", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    
    public Map<String, String> checkCnyvouDvouchenddateN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getDvouchenddate())) {
                map.put("cnybop.cnyvou.dvouchenddate", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    
    public Map<String, String> checkSaddwordvouN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getSaddwordvou())) {
                map.put("cnybop.saddwordvou", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //    开始
    //    cnybop.cnyvou.stransattr
    
    public Map<String, String> checkCnyvouStransattrN1000(CnybopVo cnybop) {
        Map<String, String> map = new HashMap<>();
        CnyvouVo cnyvouVo = cnybop.getCnyvou();
        if ("1".equals(cnybop.getVouflg())) {
            if (MdaUtils.isEmpty(cnyvouVo.getStransattr())) {
                map.put("cnybop.cnyvou.stransattr", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //cnybop.svouchername
    
    public Map<String, String> checkSvouchernameN1000(CnybopVo cnybop) {
        Map<String, String> map = new HashedMap<>();
        if ("1".equals(cnybop.getVouflg())) {
            if (MdaUtils.isEmpty(cnybop.getSvouchername())) {
                map.put("cnybop.svouchername", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //cnybop.cnyvou.cvouchdirection
    
    public Map<String, String> checkCnyvouCvouchdirectionN1000(CnybopVo cnybop) {
        Map<String, String> map = new HashedMap<>();
        CnyvouVo cnyvouVo = cnybop.getCnyvou();
        if ("1".equals(cnybop.getVouflg())) {
            if (MdaUtils.isEmpty(cnyvouVo.getCvouchdirection())) {
                map.put("cnybop.cnyvou.cvouchdirection", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //    cnybop.svoucheename
    
    public Map<String, String> checkSvoucheenameN1000(CnybopVo cnybopVo) {

        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getSvoucheename())) {
//                Platform.errorMandatory();
                map.put("cnybop.svoucheename", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //    cnybop.sdebtorname
    
    public Map<String, String> checkSdebtornameN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getSdebtorname())) {
//                Platform.errorMandatory();
                map.put("cnybop.sdebtorname", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //cnybop.cnyvou.cvouchtype
    
    public Map<String, String> checkCnyvouCvouchtypeN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(cnybopVo.getVouflg(), "1") == 0) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getCvouchtype())) {
//                Platform.errorMandatory();
                map.put("cnybop.cnyvou.cvouchtype", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    //    cnybop.cnyvou.fvouchamt
    
    public Map<String, String> checkCnyvouFvouchamtN1000(CnybopVo cnybopVo) {
        CnyvouVo cnyvouVo = cnybopVo.getCnyvou();
        Map<String, String> map = new HashedMap<>();
        if ("1".equals(cnybopVo.getVouflg()) && Objects.isNull(cnyvouVo.getFvouchamt())) {
            map.put("cnybop.cnyvou.fvouchamt", I18nUtil.getMessage("0002"));
        }
        return map;
    }
    //结束
    
    public Map<String, String> checkSbanknameN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();

        if ("1".equals(cnybopVo.getCnyflg()) || "1".equals(cnybopVo.getOutflg()) || "1".equals(cnybopVo.getLibflg()) || "1".equals(cnybopVo.getVouflg())) {
            if (StringUtils.isEmpty(cnybopVo.getSbankname())) {
                map.put("cnybop.Sbankname", I18nUtil.getMessage("0002"));
            }
        }


        return map;
    }

    
    public Map<String, String> checkCnyvouScontractnoN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();

        if ("1".equals(cnybopVo.getVouflg())) {
            if (StringUtils.isEmpty(cnybopVo.getCnyvou().getScontractno())) {
                map.put("cnybop.Cnyvou.Scontractno", I18nUtil.getMessage("0002"));
            }
        }


        return map;
    }

    
    public Map<String, String> checkCnyvouCurrencycodeN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();

        if ("1".equals(cnybopVo.getVouflg())) {
            if (StringUtils.isEmpty(cnybopVo.getCnyvou().getCurrencycode())) {
                map.put("cnybop.Cnyvou.Currencycode", I18nUtil.getMessage("0002"));
            }
        }


        return map;
    }

    
    public Map<String, String> checkCnyvouDvouchefficientdateN1000(CnybopVo cnybopVo) {
        Map<String, String> map = new HashMap<>();

        if ("1".equals(cnybopVo.getVouflg())) {
            if (MdaUtils.isEmpty(cnybopVo.getCnyvou().getDvouchefficientdate())) {
                map.put("cnybop.Cnyvou.Dvouchefficientdate", I18nUtil.getMessage("0002"));
            }
        }


        return map;
    }
}
