package com.brilliance.isc.common.transaction.newcheck.trtcre;

import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.transaction.newcheck.AbstractModuleValidator;
import com.brilliance.isc.common.transaction.newcheck.ValidResult;
import com.brilliance.isc.common.transaction.newcheck.Validate;
import com.brilliance.isc.vo.model.DinmodVo;
import com.brilliance.isc.vo.model.FinmodVo;
import com.brilliance.mda.runtime.mda.util.Inis;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.math.BigDecimal;

@Component
public class DinmodValidator extends AbstractModuleValidator<DinmodVo> {

    @Override
    @PostConstruct
    public void register() {
        super.register();
    }

    /**
     *   source:dinmod.0002.script
     */
    @Validate(path = "finmod.dinmod.shpjgh")
    public ValidResult checkShpjghN1000(DinmodVo dinmodVo){
        //!应刘文青要求，2016/10/27，审批价格（含税）、审批价格（不含税）大于0
        String openflg = Inis.getIniBlock("intace.ini","INFCPC3","open");
        if(MdaUtils.compareTo(SettleContext.getTransName(),"TRTOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(),"BPTOPN") == 0) {
            if(MdaUtils.compareTo(dinmodVo.getVisflg(),"X") == 0) {
                if( MdaUtils.compareTo(openflg,"Y") == 0 ) {
                    if(dinmodVo.getShpjgh().compareTo(BigDecimal.ZERO) <= 0) {
                        return ValidResult.build(false, "审批价格（含税）应大于0");
                    }
                }
            }
        }
        /**
         if GetFramename == "BRTSET" or GetFramename == "BDTSET" or GetFramename == "BCTSET" then

         **/
        if(MdaUtils.compareTo(SettleContext.getDirectTransName(),"BRTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BDTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BCTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"CPTOPN") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"CPTATO") == 0) {
            FinmodVo finmodVo = (FinmodVo)getParent();
            String crefinflg = finmodVo.getRec().getCrefinflg();
            if(!MdaUtils.isEmpty(crefinflg) && MdaUtils.compareTo(dinmodVo.getVisflg(), "X") == 0) {
                if( MdaUtils.compareTo(openflg,"Y") == 0 ) {
                    if(dinmodVo.getShpjgh().compareTo(BigDecimal.ZERO) <= 0) {
                        return ValidResult.build(false, "审批价格（含税）应大于0");
                    }
                }
            }
        }
        return null;
    }

    /**
     *   source:dinmod.0003.script
     */
    @Validate(path = "finmod.dinmod.shpijg")
    public ValidResult checkShpijgN1000(DinmodVo dinmodVo){
        //!应刘文青要求，2016/10/27，审批价格（含税）、审批价格（不含税）大于0
        String openflg = Inis.getIniBlock("intace.ini","INFCPC3","open");
        if(MdaUtils.compareTo(SettleContext.getTransName(),"TRTOPN") == 0 || MdaUtils.compareTo(SettleContext.getTransName(),"BPTOPN") == 0) {
            if( MdaUtils.compareTo(dinmodVo.getVisflg(),"X") == 0 ) {
                if( MdaUtils.compareTo(openflg,"Y") == 0 ) {
                    if(dinmodVo.getShpijg().compareTo(BigDecimal.ZERO) <= 0) {
                        return ValidResult.build(false, "审批价格（不含税）应大于0");
                    }
                }
            }
        }
        /**
         if GetFramename == "BRTSET" or GetFramename == "BDTSET" or GetFramename == "BCTSET" then

         **/
        if(MdaUtils.compareTo(SettleContext.getDirectTransName(),"BRTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BDTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BCTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"CPTOPN") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"CPTATO") == 0) {
            FinmodVo finmodVo = (FinmodVo)getParent();
            String crefinflg = finmodVo.getRec().getCrefinflg();
            if(!MdaUtils.isEmpty(crefinflg) && MdaUtils.compareTo(dinmodVo.getVisflg(),"X") == 0) {
                if( MdaUtils.compareTo(openflg,"Y") == 0 ) {
                    if(dinmodVo.getShpijg().compareTo(BigDecimal.ZERO) <= 0) {
                        return ValidResult.build(false, "审批价格（不含税）应大于0");
                    }
                }
            }
        }
        return null;
    }

    /**
     *   source:dinmod.0005.script
     */
    @Validate(path="finmod.dinmod.rmbsbs")
    public ValidResult checkRmbsbsN1000(DinmodVo dinmodVo){
        //国结需要支持LPR
        /**
         if GetFramename == "TRTOPN" or GetFramename == "BPTOPN" or GetFramename == "BRTSET" or GetFramename == "BDTSET" or GetFramename == "BCTSET" then

         **/
        if(MdaUtils.compareTo(SettleContext.getDirectTransName(),"TRTOPN") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BPTOPN") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BRTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BDTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"BCTSET") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"CPTOPN") == 0 || MdaUtils.compareTo(SettleContext.getDirectTransName(),"CPTATO") == 0) {
            if(!MdaUtils.isEmpty(dinmodVo.getRmbsbs())) {
                /**
                 if RMBSBS <> "0" then
                 PromptOK( 'L0000013' )
                 endif

                 **/
                if( MdaUtils.compareTo(dinmodVo.getRmbsbs(),"0") != 0 && MdaUtils.compareTo(dinmodVo.getRmbsbs(),"1") != 0 ) {
                    return ValidResult.build(false, "国结系统暂不支持央行基准或市场LPR基准以外的其他基准利率，请重新定价");
                }
            }
        }
        return null;
    }
}
