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.vo.AddbcbVo;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Component
public class AddbcbCheck implements ICheck<AddbcbVo> {

    
    public Map<String, String> check(AddbcbVo vo) {
        Map<String, String> maps = new HashMap<>();
        maps.putAll(checkBccls1N1000(vo));
        maps.putAll(checkBccls3N1000(vo));
        maps.putAll(checkBccls4N1000(vo));
        maps.putAll(checkBccls2N1000(vo));
        maps.putAll(checkPreexpdatN1000(vo));
        maps.putAll(checkGitamermkN1000(vo));
        maps.putAll(checkGitamechoN1000(vo));
        maps.putAll(checkExpdatN1000(vo));
        maps.putAll(checkLabel5N1000(vo));
        maps.putAll(checkPwtyp9N1000(vo));
        maps.putAll(checkBcbtyp7N1000(vo));
        maps.putAll(checkAmeadvrmkN1000(vo));
        maps.putAll(checkLitameadvN1000(vo));
        return maps;
    }

    
    public Map<String, String> checkBccls1N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0 && MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) != 0) {
            if ((MdaUtils.compareTo(SettleContext.getTransName(), "GITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITODZ") == 0) && MdaUtils.isEmpty(addbcbVo.getBccls1())) {
                // Platform.errorMandatory();
                map.put("addbcb.bccls1", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }

    
    public Map<String, String> checkBccls3N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0 && MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) != 0) {
            if ((MdaUtils.compareTo(SettleContext.getTransName(), "GITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITODZ") == 0) && MdaUtils.isEmpty(addbcbVo.getBccls3())) {
                // Platform.errorMandatory();
                map.put("addbcb.bccls3", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkBccls4N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0 && MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) != 0) {
            if (MdaUtils.compareTo(SettleContext.getTransName(), "GITAME") == 0 && MdaUtils.isEmpty(addbcbVo.getBccls4())) {
                // Platform.errorMandatory();
                map.put("addbcb.bccls4", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkBccls2N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0 && MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) != 0) {
            if ((MdaUtils.compareTo(SettleContext.getTransName(), "GITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITODZ") == 0) && MdaUtils.isEmpty(addbcbVo.getBccls2())) {
                // Platform.errorMandatory();
                map.put("addbcb.bccls2", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkPreexpdatN1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0 && MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) != 0) {
            if ((MdaUtils.compareTo(SettleContext.getTransName(), "GITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITODZ") == 0) && MdaUtils.isEmpty(addbcbVo.getPreexpdat())) {
                /*
                 if FRAME == "GITOPN" and IsVisible( PREEXPDAT ) and IsEmpty then
                 */
                // Platform.errorMandatory();
                map.put("addbcb.preexpdat", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkGitamermkN1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        //2009新需求，收单行的check自行设置
        if (!conCheck()) {
            return map;
        }
        if (MdaUtils.compareTo(SettleContext.getTransName(), "GITAME") == 0) {
            if ((MdaUtils.compareTo(addbcbVo.getGitamecho(), "无特殊规定") != 0)) {
                if (MdaUtils.isEmpty(addbcbVo.getGitamermk())) {
                    map.put("addbcb.gitamermk", I18nUtil.getMessage("0002"));
                }
            }
        }
        return map;
    }


    public Map<String, String> checkGitamechoN1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        //2009新需求，收单行的check自行设置
        if (!conCheck()) {
            return map;
        }
        if (MdaUtils.compareTo(SettleContext.getTransName(), "GITAME") == 0) {
            if (MdaUtils.isEmpty(addbcbVo.getGitamecho())) {
                // Platform.errorMandatory();
                map.put("addbcb.gitamecho", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkExpdatN1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") == 0 && MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) != 0) {
            if ((MdaUtils.compareTo(SettleContext.getTransName(), "GITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITODZ") == 0) && MdaUtils.isEmpty(addbcbVo.getExpdat())) {
                // Platform.errorMandatory();
                map.put("addbcb.expdat", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkLabel5N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        BigDecimal sKZCPCT = BigDecimal.ZERO;
        //2009新需求，收单行的check自行设置
        if (!conCheck()) {
            return map;
        }
        if (MdaUtils.compareTo(SettleContext.getTransName(), "LITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "GITODZ") == 0) {
            if (MdaUtils.compareTo(sKZCPCT, 100) < 0 && MdaUtils.isEmpty(addbcbVo.getLabel5())) {
                // Platform.errorMandatory();
                map.put("addbcb.label5", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkPwtyp9N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getTransName(), "LITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "LITAME") == 0) {
            if ((!MdaUtils.isEmpty(addbcbVo.getPwtyp8())) && MdaUtils.isEmpty(addbcbVo.getPwtyp9())) {
                // Platform.errorMandatory();
                map.put("addbcb.pwtyp9", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkBcbtyp7N1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getTransName(), "LITOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(), "LITAME") == 0) {
            if ((!MdaUtils.isEmpty(addbcbVo.getBcbtyp6())) && MdaUtils.isEmpty(addbcbVo.getBcbtyp7())) {
                // Platform.errorMandatory();
                map.put("addbcb.bcbtyp7", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkAmeadvrmkN1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getTransName(), "LITAME") == 0) {
            if (MdaUtils.compareTo(addbcbVo.getLitameadv(), "有特殊规定，条件为： ") == 0 && MdaUtils.isEmpty(addbcbVo.getAmeadvrmk())) {
                // Platform.errorMandatory();
                map.put("addbcb.ameadvrmk", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public Map<String, String> checkLitameadvN1000(AddbcbVo addbcbVo) {
        Map<String, String> map = new HashMap<>();
        if (MdaUtils.compareTo(SettleContext.getTransName(), "LITAME") == 0) {
            if (MdaUtils.isEmpty(addbcbVo.getLitameadv())) {
                // Platform.errorMandatory();
                map.put("addbcb.litameadv", I18nUtil.getMessage("0002"));
            }
        }
        return map;
    }


    public boolean conCheck() {
        //如果是收单行做业务则返回false
        //其他返回true
        if (MdaUtils.compareTo(SettleContext.getUserSession().getBch().getLev(), "0") == 0 || MdaUtils.isEmpty(SettleContext.getUserSession().getBch().getBranch())) {
            return true;
        }
        return MdaUtils.compareTo(SettleContext.getUserSession().getAtp().getNegflg(), "X") != 0 || MdaUtils.compareTo(SettleContext.getUserSession().getBch().getBchkey(), SettleContext.getUserSession().getBch().getBranch()) == 0;

    }
}
