package kcg.faics.report.service.impl;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import kcg.faics.report.service.ReportCategoryService;
import kcg.faics.report.vo.ReportCategoryVO;

/**
 * 견문 분류 관련 비즈니스로직
 * @author 하영지
 *
 */
@Service("reportCategoryService")
public class ReportCategoryServiceImpl implements ReportCategoryService {

	/**
	 * 견문 분류 관련 Mapper 클래스.
	 */
	@Resource(name = "reportCategoryMapper")
	private ReportCategoryMapper reportCategoryMapper;
	

	

	@Override
	public List<ReportCategoryVO> select(final int type) throws Exception {
		try {
			return reportCategoryMapper.select(type);
		} catch (Exception e) {
			return null;
		}
	}
	
	@Override
	public List<ReportCategoryVO> useSelect(final int type) throws Exception {
		try {
			return reportCategoryMapper.useSelect(type);
		} catch (Exception e) {
			return null;
		}
	}
	
	

	@Override
	public HashMap<String, String> getCategory1() throws Exception {
		return convertMap(select(1));
	}

	@Override
	public HashMap<String, String> getCategory2() throws Exception {
		return convertMap(select(2));
	}

	@Override
	public HashMap<String, String> getCategory3() throws Exception {
		return convertMap(select(3));
	}

	@Override
	public HashMap<String, String> getCategory4() throws Exception {
		return convertMap(select(4));
	}
	
	
	@Override
	public HashMap<String, String> getUseCategory1() throws Exception {
		return convertMap(useSelect(1));
	}

	@Override
	public HashMap<String, String> getUseCategory2() throws Exception {
		return convertMap(useSelect(2));
	}

	@Override
	public HashMap<String, String> getUseCategory3() throws Exception {
		return convertMap(useSelect(3));
	}

	@Override
	public HashMap<String, String> getUseCategory4() throws Exception {
		return convertMap(useSelect(4));
	}
	
	/**
	 * 맵으로 변환
	 * @param list 분류목록 
	 * @return ("코드명", "코드") 형식으로 리턴
	 */
	private HashMap<String, String> convertMap(final List<ReportCategoryVO> list) {
		HashMap<String, String> map = new HashMap<String, String>();
		for (ReportCategoryVO item : list) {
			map.put(item.getCode(), item.getName());
		}
		return map;
	}
	
}
