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.Field32B;
import com.prowidesoftware.swift.model.field.Field33B;
import com.prowidesoftware.swift.model.field.Field34B;
import com.prowidesoftware.swift.model.mt.mt7xx.MT747;


public class MT747Validator extends AbsMTValidator {
    public MT747Validator(String mtStr, MtResult mtResult) {
        super(mtStr,mtResult);
    }
    @Override
    public void bussinessValidator() {
        //  MtResult mtResult=getMtResult();
        MT747 mt720= (MT747) this.getAbstractMT();

        //C1 At least one of the fields 31E, 32B, 33B, 34B, 39A, 39C, 72Z or 77 must be present (Error code(s): C15).
            //字段31E、32B、33B、34B、39A、39C72Z或77中的至少一个必须存在,请检查!(错误代码：C15)。
       if(mt720.getField31E()==null && mt720.getField32B()==null &&
          mt720.getField33B()==null && mt720.getField34B()==null &&
          mt720.getField39A()==null && mt720.getField39C()==null &&
          mt720.getField72Z()==null && mt720.getField77()==null){
           mtResult.addDescription(Language.getLanguage("MT747_C1","[MT747]："));
        }
       //C2 If either field 32B or 33B is present, then field 34B must also be present (Error code(s): C12).
           //字段32B或字段33B存在，字段34B必须存在，请检查!(错误代码：C12)。
        if (mt720.getField32B()!=null || mt720.getField33B()!=null){
            if (mt720.getField34B()==null){
                mtResult.addDescription(Language.getLanguage("MT747_C2","[MT747]："));
            }
        }
        //C3 If field 34B is present, either field 32B or 33B must also be present (Error code(s): C12).
            //字段34B存在，字段32B或字段33B中的任何一个也必须存在，请检查!(错误代码：C12)。
        if (mt720.getField34B()!=null){
            if (mt720.getField32B()==null && mt720.getField33B()==null){
                mtResult.addDescription(Language.getLanguage("MT747_C3","[MT747]："));
            }
        }
        //C4 The currency code in the amount fields 32B, 33B and 34B must be the same (Error code(s): C02).
            //字段32B、33B和34B中的货币代码必须相同，请检查!(错误代码：C02)。
        Field32B field32B = mt720.getField32B();
        Field33B field33B = mt720.getField33B();
        Field34B field34B = mt720.getField34B();
        String field32BCurrency = "";
        String field33BCurrency = "";
        String field34BCurrency = "";
        if (field32B!=null){
            field32BCurrency = field32B.getCurrency();
        }
        if (field33B!=null){
            field33BCurrency = field33B.getCurrency();
        }
        if (field34B!=null){
            field34BCurrency = field34B.getCurrency();
            if (!field32BCurrency.equals(field34BCurrency) ||
                    !field33BCurrency.equals(field34BCurrency)){
                mtResult.addDescription(Language.getLanguage("MT747_C4","[MT747]："));
            }
        }

        //  return mtResult;
    }
}
