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

import com.brilliance.isc.common.context.SettleContext;
import com.brilliance.isc.common.rmbbop.vo.Rmbbop;
import com.brilliance.isc.common.rmbbop.vo.RmbbopRequest;
import com.brilliance.isc.common.transaction.newcheck.AbstractModuleValidator;
import com.brilliance.isc.common.transaction.newcheck.Warning;
import com.brilliance.isc.common.transaction.newcheck.WarningResult;
import com.brilliance.isc.common.transaction.newcheck.bopset.rmbbop.*;
import com.brilliance.isc.vo.lc.BrdBizInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * RMB报送检核
 */
@Component
public class RmbbopValidator extends AbstractModuleValidator<RmbbopRequest> {

    @Autowired
    private Rmb2101Validator rmb2101Validator;
    @Autowired
    private Rmb2106Validator rmb2106Validator;
    @Autowired
    private Rmb2111Validator rmb2111Validator;
    @Autowired
    private Rmb2112Validator rmb2112Validator;
    @Autowired
    private Rmb2122Validator rmb2122Validator;
    @Autowired
    private Rmb2123Validator rmb2123Validator;

    @Override
    @PostConstruct
    public void register() {
        super.register();
        rmb2101Validator.register();
        rmb2106Validator.register();
        rmb2111Validator.register();
        rmb2112Validator.register();
        rmb2122Validator.register();
        rmb2123Validator.register();
    }

    @Override
    public Map<String, String> validate(RmbbopRequest rmbbopRequest) {
        Map<String, String> maps = super.validate(rmbbopRequest);
        Rmbbop rmbbop = rmbbopRequest.getRmbbop();
        rmb2101Validator.registerParent(rmbbopRequest);
        if (StringUtils.equals(rmbbop.getRmb2101().getRmbflg(), "1")) {
            maps.putAll(rmb2101Validator.validate(rmbbop.getRmb2101()));
        }
        rmb2101Validator.removeTl();
        rmb2106Validator.registerParent(rmbbopRequest);
        if (StringUtils.equals(rmbbop.getRmb2106().getRmbflg(), "1")) {
            maps.putAll(rmb2106Validator.validate(rmbbop.getRmb2106()));
        }
        rmb2106Validator.removeTl();
        rmb2111Validator.registerParent(rmbbopRequest);
        if (StringUtils.equals(rmbbop.getRmb2111().getRmbflg(), "1")) {
            maps.putAll(rmb2111Validator.validate(rmbbop.getRmb2111()));
        }
        rmb2111Validator.removeTl();
//        rmb2112Validator.registerParent(rmbbopRequestVo);
        if (StringUtils.equals(rmbbop.getRmb2112().getRmbflg(), "1")) {
            maps.putAll(rmb2112Validator.validate(rmbbop.getRmb2112()));
        }
//        rmb2112Validator.removeTl();
        rmb2122Validator.registerParent(rmbbopRequest);
        if (StringUtils.equals(rmbbop.getRmb2122().getRmbflg(), "1")) {
            maps.putAll(rmb2122Validator.validate(rmbbop.getRmb2122()));
        }
        rmb2122Validator.removeTl();
//        rmb2123Validator.registerParent(rmbbopRequestVo);
        if (StringUtils.equals(rmbbop.getRmb2123().getRmbflg(), "1")) {
            maps.putAll(rmb2123Validator.validate(rmbbop.getRmb2123()));
        }
//        rmb2123Validator.removeTl();
        return maps;
    }

    @Warning(path = "rmbbop.rmb2111.rmbflg")
    public WarningResult checkRmbflg(RmbbopRequest rmbbopRequest) {
        String transName = SettleContext.getTransName().toUpperCase();
//        if ("1".equals(rmb2111.getRmbflg())) {
        if ("BRTSET".equals(transName.substring(0, 6))) {
            BrdBizInfoVo bizInfoVo = (BrdBizInfoVo) rmbbopRequest.getRec();
            if ("X".equals(bizInfoVo.getDkflg())) {
                return WarningResult.build("CHECKRMBFLG", "请提示代开信用证委托行报送2111!");
            }
//            }
        }
        return WarningResult.buildEmpty("CHECKRMBFLG");
    }

//    @Validate(path="rmbbop.rmbbop2122Vo.rmbflg")
//    public ValidResult checkrmb2122Vombflg(RmbbopRequestVo rmbbopRequestVo) {
//
//        String frm = SettleContext.getTransName();
//        switch (frm) {
//            case "GITOPN":
//            case "GITODZ":
//            case "GETOPN":
//                /**
//                 case "GITOPN"
//                 **/
//                if (MdaUtils.isEmpty(rmbbopRequestVo.getRmbbop2122Vo().getRmbflg())) {
//                    return ValidResult.build(false, "必输项");
//                }
//        }
//        return null;
//    }


}
