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

import com.brilliance.isc.swift.objmtconvert.model.AbsMTValidator;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;
import com.brilliance.isc.swift.objmtconvert.util.Language;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field32A;
import com.prowidesoftware.swift.model.field.Field32B;
import com.prowidesoftware.swift.model.field.Field32K;
import com.prowidesoftware.swift.model.field.Field33A;
import com.prowidesoftware.swift.model.mt.mt4xx.MT400;

import java.util.List;

/**
 * @author zh
 * @create 2023-03-03-10:27
 */
public class MT400Validator extends AbsMTValidator {

    public MT400Validator(String mtStr, MtResult mtResult)
    {
        super(mtStr,mtResult);
    }

    @Override
    public void bussinessValidator() {
        //MtResult mtResult=getMtResult();
        boolean flag = false;
        boolean flag1 = false;
        boolean flag2 = false;
        List<Tag> tags = this.getAbstractMT().getSwiftMessage().getBlock4().getTags();
        for (Tag tag : tags) {
            if(tag.getName().contains("53")){
                flag1 = true;
            }
            if(tag.getName().contains("54")){
                flag2 = true;
            }
            if(tag.getName().contains("57")){
                flag = true;
            }
        }
        if(!(flag1&&flag2)){
            if(flag){
                mtResult.addDescription(Language.getLanguage("MT400_C1","【MT400】"));
            }
        }
        MT400 mt400 = (MT400) this.getAbstractMT();
        Field32A field32A = mt400.getField32A();
        Field32B field32B = mt400.getField32B();
        Field32K field32K = mt400.getField32K();
        String field32Currency = "";
        if(field32A!=null){
            field32Currency = field32A.getCurrency();
        }
        if(field32B!=null){
            field32Currency = field32B.getCurrency();
        }
        if(field32K!=null){
            field32Currency = field32K.getCurrency();
        }
        Field33A field33A = mt400.getField33A();
        if(field33A!=null){
            String field33Currency = field33A.getCurrency();
            if(!field32Currency.equals(field33Currency)){
                mtResult.addDescription(Language.getLanguage("MT400_C2","【MT400】"));
            }
        }

        //  return mtResult;
    }
}
