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.SwiftTagListBlock;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field56C;
import com.prowidesoftware.swift.model.mt.mt2xx.MT205COV;

import java.util.ArrayList;
import java.util.List;


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

       if(mt205COV.getSequenceA().containsTag(56)){
           if(!mt205COV.getSequenceA().containsTag(57)){
//               mtResult.addDescription("【MT205COV】A序列中56A或者56D存在，则57A或者57B或者57D也必须存在，请检查");
               mtResult.addDescription(Language.getLanguage("MT205COV_C1","【MT205COV】"));
           }
       }

      List<Tag> list=  mt205COV.getSwiftMessage().getBlock4().getTags();
        for (int i = 0; i < list.size()-1; i++) {
            if (list.get(i).getName().contains("50")) {
                for (int j = i; j < list.size() - 1; j++) {
                    if (list.get(j).getName().contains("56")) {
                        if (!list.get(j + 1).getName().contains("57")) {
//                            mtResult.addDescription("【MT205COV】B序列中56A或者56C或者56D存在，则57A或者57B或者57C或者57D也必须存在，请检查");
                            mtResult.addDescription(Language.getLanguage("MT205COV_C2","【MT205COV】"));
                            break;
                        }

                    }
                }
            }


        }

//        if(mt205COV.getSequenceB().containsTag(56)){
//            if(!mt205COV.getSequenceB().containsTag(57)){
//                mtResult.addDescription("B序列Field56a存在则Field57a也必须存在，请检查" + Constans.CRLF);
//            }
//        }
        //  return mtResult;
    }

}
