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


import com.brilliance.isc.swift.objmtconvert.model.AbsMTValidator;
import com.brilliance.isc.swift.objmtconvert.result.MtResult;
import com.brilliance.isc.swift.objmtconvert.util.Constans;
import com.brilliance.isc.swift.objmtconvert.util.Language;
import com.prowidesoftware.swift.model.field.Field19;
import com.prowidesoftware.swift.model.field.Field32B;
import com.prowidesoftware.swift.model.mt.mt2xx.MT204;

import java.math.BigDecimal;
import java.util.List;


public class MT204Validator extends AbsMTValidator {
    public MT204Validator(String mtStr, MtResult mtResult) {
        super(mtStr,mtResult);
    }
    @Override
    public void bussinessValidator() {
        //MtResult mtResult=getMtResult();
        MT204 mt204= (MT204) this.getAbstractMT();
        List<Field32B> field32B = mt204.getField32B();
        //19为循环内32金额之和
        Field19 field19 = mt204.getField19();    //sum of amount
        BigDecimal sum = new BigDecimal("0");
        for (Field32B temp:field32B) {
            sum=sum.add(temp.amount());
            //循环域内32B币种相同
            if(!temp.getCurrency().equals(field32B.get(0).getCurrency()) ){
//                mtResult.addDescription("【MT204】中循环域内Field32B金额类型需保持一致，请检查");
                mtResult.addDescription(Language.getLanguage("MT204_C1","【MT204】"));
            }
        }
        if(!field19.amount().equals(sum)){
//            mtResult.addDescription("【MT204】中Field19表示总金额，需与Field32B金额总和一致，请检查");
            mtResult.addDescription(Language.getLanguage("MT204_C2","【MT204】"));
        }
        //循环域不超过10   ，（32B必填）
       if( field32B.size()>10){
//           mtResult.addDescription("【MT204】中循环域至多10个，请检查");
           mtResult.addDescription(Language.getLanguage("MT204_C3","【MT204】"));
       }

      //  return  mtResult;
    }
}
