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

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.field.*;
import com.prowidesoftware.swift.model.mt.mt9xx.MT941;

import java.util.List;

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

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

    @Override
    public void bussinessValidator() {
        // MtResult mtResult=getMtResult();
        MT941 mt941 = (MT941) this.getAbstractMT();
        Field62F field62F = mt941.getField62F();
        boolean flag = false;
        String field62FCurrency = "";
        if(field62F!=null){
            field62FCurrency = field62F.getCurrency().substring(0,2);
        }
        Field60F field60F = mt941.getField60F();
        if(field60F!=null){
            String field60FCurrency = field60F.getCurrency().substring(0,2);
            if(!field60FCurrency.equals(field62FCurrency)){
                flag = true;
            }
        }
        Field90D field90D = mt941.getField90D();
        if(field90D!=null){
            String field90DCurrency = field90D.getCurrency().substring(0,2);
            if(!field62FCurrency.equals(field90DCurrency)){
                flag = true;
            }
        }
        Field90C field90C = mt941.getField90C();
        if(field90C!=null){
            String field90CCurrency = field90C.getCurrency().substring(0,2);
            if(!field62FCurrency.equals(field90CCurrency)){
                flag = true;
            }
        }
        Field64 field64 = mt941.getField64();
        if(field64!=null){
            String field64Currency = field64.getCurrency().substring(0,2);
            if(!field64Currency.equals(field62FCurrency)){
                flag = true;
            }
        }
        List<Field65> listField65 = mt941.getField65();
        if(listField65!=null){
            for (Field65 field65 : listField65) {
                String field65Currency = field65.getCurrency().substring(0,2);
                if(!field65Currency.equals(field62FCurrency)){
                    flag = true;
                }
            }
        }
        if(flag){
            mtResult.addDescription(Language.getLanguage("MT941_C1","【MT941】"));
        }
        //   return mtResult;
    }
}
