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

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.mt7xx.MT765;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;

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

    @Override
    public void bussinessValidator() {
        MT765 mt765 = (MT765) this.getAbstractMT();
        //C1:如果字段49A为INCP。那么字段77必须存在，否则不允许字段77 (错误代码:C13)
        Field49A field49A =mt765.getField49A();
        Field77 field77= mt765.getField77();
        Field22G field22G=mt765.getField22G();
        Field31E field31E=mt765.getField31E();
        String field49AValue="";
        String field22GValue="";
        if (field49A!=null){
            field49AValue=field49A.getValue();
        }
        if (field49AValue.contains("INCP")){
            if (field77==null|| StringUtils.isEmpty(field77.getValue())){
                mtResult.addDescription(Language.getLanguage("MT765_C1","【MT765校验失败】:"));
                return ;
            }
        }

        //c2:如果字段22G是PAYM，则字段不允许使用31E(错误代码:C17)。
        if (field22G!=null){
            field22GValue=field22G.getValue();
        }
        if (field22GValue.contains("PAYM")){
            if (field31E!=null&& StringUtils.isNotEmpty(field77.getValue())){
                mtResult.addDescription(Language.getLanguage("MT765_C2","【MT765校验失败】:"));
                return ;
            }
        }
    }
}
