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.*;
import com.prowidesoftware.swift.model.mt.mt2xx.MT201;
import org.apache.commons.lang3.StringUtils;

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


public class MT201Validator extends AbsMTValidator {
    public MT201Validator(String mtStr, MtResult mtResult) {
        super(mtStr,mtResult);
    }
    @Override
    public void bussinessValidator() {
       // MtResult mtResult=getMtResult();
        MT201 mt201= (MT201) this.getAbstractMT();
        List<Field32B> field32B = mt201.getField32B();        //19为循环内32金额之和
        Field19 field19 = mt201.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("【MT210】中循环域内Field32B金额类型需保持一致，请检查");
              mtResult.addDescription(Language.getLanguage("MT201_C1","【MT201】"));
          }
        }
        if(!field19.amount().equals(sum)){
//            mtResult.addDescription("【MT210】中Field19需与32B金额总和一致，请检查");
            mtResult.addDescription(Language.getLanguage("MT201_C2","【MT201】"));
        }
        //循环域至少2，不超过10   ，（32B必填）
       if( field32B.size()<2||field32B.size()>10){
//           mtResult.addDescription("【MT210】中循环域至少2个，至多10个，请检查");
           mtResult.addDescription(Language.getLanguage("MT201_C3","【MT201】"));
       }

       // return  mtResult;
    }
}
