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.MT940;

import java.util.List;

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

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

    @Override
    public void bussinessValidator() {
        //MtResult mtResult=getMtResult();
        boolean flag = false;
        MT940 mt940 = (MT940) this.getAbstractMT();
        Field60F field60F = mt940.getField60F();
        Field60M field60M = mt940.getField60M();
        String field60Currency = "";
        if(field60F!=null){
            field60Currency = field60F.getCurrency().substring(0,2);
        }
        if(field60M!=null){
            field60Currency = field60M.getCurrency().substring(0,2);
        }
        Field62F field62F = mt940.getField62F();
        Field62M field62M = mt940.getField62M();
        String field62Currency = "";
        if(field62F!=null){
            field62Currency = field62F.getCurrency().substring(0,2);
        }
        if(field62M!=null){
            field62Currency = field62M.getCurrency().substring(0,2);
        }
        if(!field60Currency.equals(field62Currency)){
            flag = true;
        }
        Field64 field64 = mt940.getField64();
        if(field64!=null){
            String field64Currency = field64.getCurrency().substring(0,2);
            if(!field60Currency.equals(field64Currency)){
                flag = true;
            }
        }
        List<Field65> listField65 = mt940.getField65();
        if(listField65!=null&&listField65.size()>0){
            for (Field65 field65 : listField65) {
                String field65Currency = field65.getCurrency().substring(0,2);
                if(!field60Currency.equals(field65Currency)){
                    flag = true;
                }
            }
        }
        if(flag){
            mtResult.addDescription(Language.getLanguage("MT940_C2","【MT940】"));
        }
        //  return mtResult;
    }
}
