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.mt.mt7xx.MT759;

/**
 * MT759
 * @author wanggang
 * @Date 2023-03-03
 */
public class MT759Validator extends AbsMTValidator {

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

    @Override
    public void bussinessValidator() {
        //   MtResult mtResult= getMtResult();
        MT759 mt759= (MT759) this.getAbstractMT();
        //C1 If field 23H contains ISSUANCE, REQISSUE, REQAMEND, or ISSAMEND, then field 22D must contain UNDK and if field 23H contains TRANSFER, then field 22D must contain DGAR, STBY, or UNDK and if field 23H contains CLSVOPEN, CLSVCLOS, FRAUDMSG, GENINFAD, OTHERFNC, REIMBURS, or REQFINAN,then field 22D must contain DGAR, DOCR, STBY, or UNDK.(Error code(s): D87).
            //如果字段23H包含ISSUANCE、REQISSUE、REQAMEND或ISSAMEND，则字段22D必须包含UNDK;如果字段23H包含TRANSFER，则字段23D必须包含DGAR、STBY或UNDK;如果字段23H包含CLSVOPEN、CLSVCLOS、FRAUDMSG、GENINFAD、OTHERFNC、REIMBURS、或REQFINAN，则字段22D必须包含DGAR、DOCR、STBY或UNDK，（错误代码：D87）。
        if ((mt759.getField23H().getValue().contains("ISSUANCE") || mt759.getField23H().getValue().contains("REQISSUE")
        || mt759.getField23H().getValue().contains("REQAMEND") || mt759.getField23H().getValue().contains("ISSAMEND")
        ) && !(mt759.getField22D().getValue().contains("UNDK"))){
            mtResult.addDescription(Language.getLanguage("MT759_C1","[MT759]："));
        } else if ((mt759.getField23H().getValue().contains("TRANSFER")) && !(mt759.getField22D().getValue().contains("DGAR")
        || mt759.getField22D().getValue().contains("STBY") || mt759.getField22D().getValue().contains("UNDK"))) {
            mtResult.addDescription(Language.getLanguage("MT759_C1","[MT759]："));
        }else if ((mt759.getField23H().getValue().contains("CLSVOPEN") || mt759.getField23H().getValue().contains("CLSVCLOS")
        || mt759.getField23H().getValue().contains("FRAUDMSG") || mt759.getField23H().getValue().contains("GENINFAD")
        || mt759.getField23H().getValue().contains("OTHERFNC") || mt759.getField23H().getValue().contains("REIMBURS")
        || mt759.getField23H().getValue().contains("REQFINAN")) && !(mt759.getField22D().getValue().contains("DGAR")
        || mt759.getField22D().getValue().contains("DOCR") || mt759.getField22D().getValue().contains("STBY")
        ||mt759.getField22D().getValue().contains("UNDK"))){
            mtResult.addDescription(Language.getLanguage("MT759_C1","[MT759]："));
        }


        //    return  mtResult;
    }

}

