package kccf.sch.service.vo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 검색결과 컬렉션 VO
 *
 */
public class SearchCollectionVO {
	/** 컬렉션명*/
	private String CollectionName = "";
	/** 컬렉션의 총검색 건수 */
	private int totalCount = 0;
	/** 컬렉션의 반환되는 검색 건수 */
	private int resultCount = 0;
	/** 컬렉션의 검색결과 리스트 */
	private ArrayList<Map<Object ,Object>> searchResultList = null;
	
	public String getCollectionName() {
		return CollectionName;
	}

	public void setCollectionName(String collectionName) {
		CollectionName = collectionName;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getResultCount() {
		return resultCount;
	}

	public void setResultCount(int resultCount) {
		this.resultCount = resultCount;
	}
	

	@Override
	public String toString() {
		return "SearchCollectionVO [CollectionName=" + CollectionName
				+ ", totalCount=" + totalCount + ", resultCount=" + resultCount
				+ ", searchResultList=" + searchResultList + "]";
	}

	public ArrayList<Map<Object ,Object>> getSearchResultList() {
		ArrayList<Map<Object ,Object>> searchResultListRet = new ArrayList<Map<Object ,Object>>();
		searchResultListRet.addAll(searchResultList);
		return searchResultListRet;
	}

	public void setSearchResultList(ArrayList<Map<Object ,Object>> searchResultList) {
		if(searchResultList != null){
			this.searchResultList = new ArrayList<Map<Object ,Object>>();
			for(int i = 0; i < searchResultList.size(); ++i){
				this.searchResultList.add(searchResultList.get(i));
			}
		}
	}

	/**
	 * 컬렉션 단위의 xml 모양
	 * @return XML 모양의 String 값
	 * @see toXml() 에서 사용됨
	 */
	public String getXml(){
		StringBuffer xmlStr = new StringBuffer(1024);
		xmlStr.append("<collection collectionName=\""+getCollectionName()+"\">").append(System.getProperty("line.separator"));
		xmlStr.append("<totalCount><![CDATA["+ getTotalCount()+"]]></totalCount>").append(System.getProperty("line.separator"));
		xmlStr.append("<resultCount><![CDATA["+ getResultCount()+"]]></resultCount>").append(System.getProperty("line.separator"));
		xmlStr.append("<Rows>").append(System.getProperty("line.separator"));
		List<?> searchResultList = getSearchResultList();
		int searchResultListCount = searchResultList.size();
		
		/*
		for(int i = 0 ; i < SearchResultListCount ; i++){
			AbstractSearchResult resultVo = this.SearchResultList.get(i);
			xmlStr.append(resultVo.getXml());
		}
		*/
		xmlStr.append("</Rows>").append(System.getProperty("line.separator"));
		xmlStr.append("</collection>");
		return xmlStr.toString();
	}
	
	/**
	 * 컬렉션 단위의 json 모양 
	 * @return json 형태의 String 값
	 * @see toJson() 에서 사용됨
	 */
	public String getJson(){
		StringBuffer jsonBr = new StringBuffer(1024);
		jsonBr.append("{\"collection\":");
		jsonBr.append("{");
		jsonBr.append("\"totalCount\":\""+ getTotalCount()+"\",");
		jsonBr.append("\"resultCount\":\""+ getResultCount()+"\",");
		jsonBr.append("\"itemList\":[");
		List<?> searchResultList = getSearchResultList();
		int searchResultListCount =  searchResultList.size();
		for(int i  = 0 ; i < searchResultListCount ; i++){
			/*
			AbstractSearchResult resultVo = SearchResultList.get(i);
			jsonBr.append(resultVo.getJson());
			if(i != SearchResultListCount-1 ){
				jsonBr.append(",");
			}
			*/
		}
		jsonBr.append("]");
		jsonBr.append(",\"collectionName\":\""+ getCollectionName()+"\"}");
		jsonBr.append("}");
		return jsonBr.toString();
	}
	/**
	 * 컬렉션 단위의 str 모양 
	 * @return
	 */
	public String getStr(){
		StringBuffer br = new StringBuffer(1024);
		br.append("[collection][collectionName:").append(getCollectionName()).append("]").append(System.getProperty("line.separator"));
		br.append("[collection][totalCount:").append(getTotalCount()).append("]").append(System.getProperty("line.separator"));
		br.append("[collection][resultCount:").append(getResultCount()).append("]").append(System.getProperty("line.separator"));
		List<?> searchResultList = getSearchResultList();
		int searchResultListCount =  searchResultList.size();
		for(int i  = 0 ; i < searchResultListCount ; i++){
			/*
			AbstractSearchResult resultVo = SearchResultList.get(i);
			br.append("[").append(i).append("]").append(resultVo.getStr()).append(System.getProperty("line.separator"));
			*/
		}
		return br.toString();
	}
}
