package com.eactive.eai.common.b2badaptermapping;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

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

	private String eaiInstCd; // EAI 서버인스턴스명 [TSEAIFR07.EAISevrInstncName]
	private String eaiSvcCd; // EAI 서비스명 [TSEAIFR07.EAISvcName]

	private HashMap<String, B2BAdapterMapFldVO> msgFlds;

	public B2BAdapterMapVO() {
		this("", "");
	}

	public B2BAdapterMapVO(String eaiInstCd, String eaiSvcCd) {
		this.eaiInstCd = eaiInstCd;
		this.eaiSvcCd = eaiSvcCd;
		this.msgFlds = new HashMap<>();
	}

	public void setEaiInstCd(String eaiInstCd) {
		this.eaiInstCd = eaiInstCd;
	}

	public String getEaiInstCd() {
		return this.eaiInstCd;
	}

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

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

	public B2BAdapterMapFldVO getB2BAdapterMapFld(String b2bExtnlInstiCd, String bzwkVal) {
		return getB2BAdapterMapFld(b2bExtnlInstiCd + bzwkVal);
	}

	public B2BAdapterMapFldVO getB2BAdapterMapFld(String key) {
		B2BAdapterMapFldVO vo = msgFlds.get(key);
		if (vo == null)
			return null;

		return vo;
	}

	public void addB2BAdapterMapFld(String b2bExtnlInstiCd, String bzwkVal, String adapterGroupName,
			String adapterName) {
		this.msgFlds.put(b2bExtnlInstiCd + bzwkVal,
				new B2BAdapterMapFldVO(b2bExtnlInstiCd, bzwkVal, adapterGroupName, adapterName));
	}

	public void deleteB2BAdapterMapFld(String b2bExtnlInstiCd, String bzwkVal) {
		this.msgFlds.remove(b2bExtnlInstiCd + bzwkVal);
	}

	public int getB2BAdapterMapFldLength() {
		return this.msgFlds.size();
	}

	public String[] getAllKeyNames() {
		Iterator<String> it = this.msgFlds.keySet().iterator();
		String[] name = new String[this.msgFlds.size()];
		for (int i = 0; it.hasNext(); i++) {
			name[i] = it.next();
		}
		Arrays.sort(name);
		return name;
	}

	public Collection<B2BAdapterMapFldVO> getB2BAdapterMapFlds() {
		return msgFlds.values();
	}
}
