package com.brilliance.isc.swift.objmtconvert.model.busvalidator.mt1xx;

import com.brilliance.isc.swift.objmtconvert.model.AbsMTValidator;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;
import com.brilliance.isc.swift.objmtconvert.util.Constans;
import com.brilliance.isc.swift.objmtconvert.util.Language;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.field.Field32A;
import com.prowidesoftware.swift.model.field.Field32B;
import com.prowidesoftware.swift.model.mt.mt1xx.MT110;

import java.util.List;

public class MT110Validator extends AbsMTValidator {
    public MT110Validator(String mtStr, MtResult mtResult)
    {
        super(mtStr,mtResult);
    }

    @Override
    public void bussinessValidator() {
       // MtResult mtResult=getMtResult();
        MT110 mt110=(MT110) this.getAbstractMT();

        List<Field32B> field32B= mt110.getField32B();
        List<Field32A> field32A= mt110.getField32A();

        //C1:重复序列不能出现超过十次(错误代码:T10)
            if(field32B.size()>10||field32A.size()>10||((field32B.size()+field32A.size())>10)){
                mtResult.addDescription(Language.getLanguage("MT110_C1","【MT110】"));
                return ;
            }
        mt1xxField32(field32A,field32B,mtResult);

    }

    public static void mt1xxField32(List<Field32A> listField32A, List<Field32B> listField32B, MtResult mtResult){
        String field32ACurrency = "";
        String field32BCurrency = "";
        if(listField32A!=null&&listField32A.size()>0){
            field32ACurrency = listField32A.get(0).getCurrency();
            for (Field32A field32A : listField32A) {
                if(!field32ACurrency.equals(field32A.getCurrency())){
                    mtResult.addDescription(Language.getLanguage("MT110_C2","【MT110】"));
                    return ;
                }
            }
        }
        if(listField32B!=null&&listField32B.size()>0){
            field32BCurrency = listField32B.get(0).getCurrency();
            for (Field32B field32B : listField32B) {
                if(!field32BCurrency.equals(field32B.getCurrency())){
                    mtResult.addDescription(Language.getLanguage("MT110_C2","【MT110】"));
                    return ;
                }
            }
        }

        if(StringUtil.isNotEmpty(field32ACurrency)&&StringUtil.isNotEmpty(field32BCurrency)){
            if(!field32ACurrency.equals(field32BCurrency)){
                mtResult.addDescription(Language.getLanguage("MT110_C2","【MT110】"));
                return ;
            }
        }

    }
}
