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.Constans;
import com.brilliance.isc.swift.objmtconvert.util.Language;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field32B;
import com.prowidesoftware.swift.model.field.Field33A;
import com.prowidesoftware.swift.model.field.Field33B;
import com.prowidesoftware.swift.model.field.Field34B;
import com.prowidesoftware.swift.model.mt.mt7xx.MT756;
import com.prowidesoftware.swift.model.mt.mt7xx.MT769;

import java.util.List;
import java.util.Objects;

/**
 * MT750
 * @author wanggang
 * @Date 2023-3-3
 */
public class MT769Validator extends AbsMTValidator {

    public MT769Validator(String mtStr, MtResult mtResult)
    {
        super(mtStr,mtResult);
    }

    @Override
    public void bussinessValidator() {
        // MtResult mtResult = getMtResult();
        MT769 mt769= (MT769)this.getAbstractMT();
        List<Tag> tags = this.getAbstractMT().getSwiftMessage().getBlock4().getTags();
        String field33Currency = "";
        Field33B field33B = mt769.getField33B();
        if(field33B!=null){
            field33Currency = field33B.getCurrency();
        }
        Field34B field34B = mt769.getField34B();
        if(field34B!=null){
            String field34Currency = field34B.getCurrency();
            if(!field34Currency.equals(field33Currency)){
                mtResult.addDescription(Language.getLanguage("MT769_C5","【MT769】"));
            }
        }

        if (!Objects.isNull(mt769.getField25()) && (!Objects.isNull(mt769.getField57A()) || !Objects.isNull(mt769.getField57B()) || !Objects.isNull(mt769.getField57D()))){
            mtResult.addDescription(Language.getLanguage("MT769_C1","【MT769】"));
        }
        if (!Objects.isNull(mt769.getField33B())){
            if (!Objects.isNull(mt769.getField39C())){
                mtResult.addDescription(Language.getLanguage("MT769_C2","【MT769】"));
            }
        }
        if (!Objects.isNull(mt769.getField39C())){
            if (!Objects.isNull(mt769.getField33B())){
                mtResult.addDescription(Language.getLanguage("MT769_C2","【MT769】"));
            }
        }
        if (!Objects.isNull(mt769.getField32D())){
            if (Objects.isNull(mt769.getField57A()) && Objects.isNull(mt769.getField57B()) && Objects.isNull(mt769.getField57D())){
                mtResult.addDescription(Language.getLanguage("MT769_C3","【MT769】"));
            }
        }
        boolean flag = false;
        for (Tag tag : tags) {
            if (tag.getName().contains("71D")) {
                flag = true;
            }
            if (flag){
                if (mt769.getField32B() == null && mt769.getField32D() == null) {
                    mtResult.addDescription(Language.getLanguage("MT769_C4","【MT769】"));
                }
                return ;
            }
        }
    //    return  mtResult;
    }

}
