package com.eactive.eai.rms.onl.manage.serviceinfo.itsm.vo;

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

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.collections.keyvalue.MultiKey;
import org.apache.commons.collections.map.MultiKeyMap;

@XmlRootElement(name = "adapterStatus")
@XmlAccessorType(XmlAccessType.FIELD)
public class AdapterStatus {
	
	@XmlElement(name = "adapter")
	private List<AdapterInfo> adapterInfoList;
	
	private String errorMsg;
	
	public AdapterStatus() { }
	
	@SuppressWarnings("unchecked")
	public static AdapterStatus mapping(MultiKeyMap adapterMap) {
		
		AdapterStatus result = new AdapterStatus();
		List<AdapterInfo> list = new ArrayList<>();
		
		adapterMap.forEach((k, v) -> {
			String instance = ((MultiKey) k).getKey(0).toString();
			String adapterName = ((MultiKey) k).getKey(1).toString();
			HashMap<String, Object> value = (HashMap<String, Object>) v;
			
			String instiName = (String) value.get("instiName");
			String bizName = (String) value.get("bizName");
			Boolean status = (Boolean) value.get("status");
			
			list.add(new AdapterInfo(instance, adapterName, instiName, bizName, status));
			
		});
		
		result.setAdapterInfoList(list);
		return result;
	}

	public void add(AdapterInfo adapterInfo) {
		this.adapterInfoList.add(adapterInfo);
	}

	public List<AdapterInfo> getAdapterInfoList() {
		return adapterInfoList;
	}

	public void setAdapterInfoList(List<AdapterInfo> adapterInfoList) {
		this.adapterInfoList = adapterInfoList;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

}
