package com.eactive.eai.common.bizkey;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class BizKeyVO implements Serializable {
	private static final long serialVersionUID = 1L;

	private String eaiSvcCd; // EAI 서비스코드 [TSEAIFR03.EAISvcName]
	private String exrClsNm; // 추출구분 		[TSEAIFR03.EtractDstcd] (추적필드(TR) | ALT-KEY(AK))

	private ArrayList<BizKeyFldVO> alMsgFlds;

	public BizKeyVO() {
		this("");
	}

	public BizKeyVO(String eaiSvcCd) {
		this(eaiSvcCd, "");
	}

	public BizKeyVO(String eaiSvcCd, String exrClsNm) {
		this.eaiSvcCd = eaiSvcCd;
		this.exrClsNm = exrClsNm;
		this.alMsgFlds = new ArrayList<>();
	}

	public void setEaiSvcCd(String eaiSvcCd) {
		this.eaiSvcCd = eaiSvcCd;
	}

	public String getEaiSvcCd() {
		return this.eaiSvcCd;
	}

	public void setExrClsNm(String exrClsNm) {
		this.exrClsNm = exrClsNm;
	}

	public String getExrClsNm() {
		return this.exrClsNm;
	}

	public BizKeyFldVO getBizKeyFld(int key) {
		BizKeyFldVO vo = alMsgFlds.get(key);
		if (vo == null)
			return null;

		return vo;
	}

	public void addBizKeyFld(String msgTp, String bwkColNm) {
		int alSize = this.alMsgFlds.size();
		this.alMsgFlds.add(new BizKeyFldVO(alSize + 1, msgTp, bwkColNm));
	}

	public void addBizKeyFld(int colPssSeq, String msgTp, String bwkColNm) {
		this.alMsgFlds.add(new BizKeyFldVO(colPssSeq, msgTp, bwkColNm));
	}

	public int getBizKeyFldLength() {
		return this.alMsgFlds.size();
	}
	
	@Override
	public String toString() {
		return "BizKeyFldVO [alMsgFlds=" + printMessageFields()  + "]";
	}
	
	private String printMessageFields() {
		StringBuilder sb = new StringBuilder();
		alMsgFlds.forEach( field -> sb.append(field.toString()).append("\n | ") );
		return sb.toString(); 
	}

	public List<BizKeyFldVO> getAlMsgFlds() {
		return alMsgFlds;
	}

}
