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.Tag;
import com.prowidesoftware.swift.model.mt.mt7xx.MT768;
import java.util.List;


public class MT768Validator extends AbsMTValidator {
    public MT768Validator(String mtStr, MtResult mtResult) {
        super(mtStr,mtResult);
    }
    @Override
    public void bussinessValidator() {
        //  MtResult mtResult = getMtResult();
        MT768 mt768 = (MT768) this.getAbstractMT();
        List<Tag> tags = this.getAbstractMT().getSwiftMessage().getBlock4().getTags();

        //C1 Either field 25 or 57a, but not both, may be present (Error code(s): C77).
            //字段25与字段57a(57A/57B/57D)不能同时存在，请检查!（错误代码：C77）。
        if (mt768.getField25()!=null){
            if (mt768.getField57A()!=null || mt768.getField57B()!=null || mt768.getField57D()!=null){
                mtResult.addDescription(Language.getLanguage("MT768_C1","[MT768]："));
            }
        }
        //C2 If field 32D is present, field 57a must not be present (Error code(s): C78).
            //字段32D存在，字段57a(57A/57B/57D)必须不存在，请检查!（错误代码：C78）。
        if (mt768.getField32D()!=null){
            if (mt768.getField57A()!=null || mt768.getField57B()!=null || mt768.getField57D()!=null){
                mtResult.addDescription(Language.getLanguage("MT768_C2","[MT768]："));
            }
        }
        //C3 If field 71D is present, field 32a must also be present (Error code(s): C33).
            //字段71D存在，则字段32a(32B/32D)必须存在，请检查!（错误代码：C78）。
        boolean flag = false;
        for (Tag tag : tags) {
            if (tag.getName().contains("71D")) {
                flag = true;
            }
            if (flag){
                if (mt768.getField32B() == null && mt768.getField32D() == null) {
                    mtResult.addDescription(Language.getLanguage("MT768_C3","[MT768]："));
                }
                return ;
            }
        }
        //  return mtResult;
    }
}
