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

import com.brilliance.isc.bo.Cnycty;
import com.brilliance.isc.common.rmbbop.entity.Tbz;
import com.brilliance.isc.common.rmbbop.vo.Rmb2112;
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.common.util.StringUtils;
import com.brilliance.isc.mda.dao.CnyctyMapper;
import com.brilliance.mda.runtime.mda.util.MdaUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

@Component
public class Rmb2112Validator extends AbstractModuleValidator<Rmb2112> {

    @Autowired
    private CnyctyMapper cnyctyMapper;

    @Autowired
    private TbzValidator tbzValidator;

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

    @Override
    public Map<String, String> validate(Rmb2112 vo) {
        Map<String, String> maps = new HashMap<>();
        maps.putAll(super.validate(vo));
        //验证备忘录条目
        List<Tbz> tbz = vo.getRecgrp().getTbz();
        for (int i = 0; i < tbz.size(); i++) {
            maps.putAll(tbzValidator.validate(tbz.get(i), i));
        }
        return maps;
    }

//    @Validate(path="rmbbop2112Vo.rmbflg")
//    public ValidResult checkRmbflgN1000(Rmbbop2112Vo rmbbop2112Vo){
//        switch( SettleContext.getTransName().toUpperCase() )
//        {
//            case  "GETSET":
//                if( MdaUtils.isEmpty(rmbbop2112Vo.getRmbflg()) )
//                {
//                    return ValidResult.build(false, "必输项");
//                }
//                break;
//        }
//
//        return null;
//    }


    @Validate(path="rmbbop.rmb2112.recgrp.ads.payercountrycode")
    public ValidResult checkpayercountrycodeN1000(Rmb2112 rmb2112) {
        String countryCod = rmb2112.getRecgrp().getAds().getPayercountrycode();
        if(StringUtils.isEmpty(countryCod)){
            return errorMandatory();
        }else {
            Cnycty cnycty = cnyctyMapper.getCnyctyByCode(countryCod);
            if(MdaUtils.isEmpty(cnycty)){
                return ValidResult.build(false, "请输入正确的付款人常驻国家（地区）代码cod");
            }
            return null;
        }
    }

}
