package com.brilliance.isc.swift.objmtconvert.model.commontag;

import com.brilliance.isc.swift.objmtconvert.util.Constans;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author gechengyang
 * @date 2023/2/20
 */
public class TagResult {

    private String tagBefore="";//51

    private String tagEnd="";//A D
    private String value;//   /6226TEST00001

    private  List<String> tagDspList=new LinkedList<>();

    private Map<String,Object> tagValueMap; //存放对应属性中字段的key和value

    public Map<String, Object> getTagValueMap() {
        return tagValueMap;
    }

    public void setTagValueMap(Map<String, Object> tagValueMap) {
        this.tagValueMap = tagValueMap;
    }

    public void setTagBefore(String tagBefore) {
        this.tagBefore = tagBefore;
    }

    public List<String> getTagDspList() {
        return tagDspList;
    }

    public void setTagDspList(List<String> tagDspList) {
        this.tagDspList = tagDspList;
    }

    public String getTagBefore() {
        return tagBefore;
    }


    public String getTagEnd() {
        return tagEnd;
    }

    public void setTagEnd(String tagEnd) {
        this.tagEnd = tagEnd;
    }

    public TagResult(String tagBefore) {
        this.tagBefore = tagBefore;
    }

    public TagResult() {
    }

    public String getValue() {
        if(StringUtils.isEmpty(value)){
            toResult();
        }
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    private  void toResult() {
        String separator= Constans.CRLF;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < tagDspList.size(); i++) {
            sb.append(tagDspList.get(i)).append(separator);
        }
        this.value= tagDspList.isEmpty() ? "" : sb.toString().substring(0, sb.toString().length() - 2);
    }
}
