package com.eactive.eai.custom.stderrorcode;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.common.dao.BaseDAO;
import com.eactive.eai.common.dao.DAOException;
import com.eactive.eai.common.exception.ExceptionUtil;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.custom.stderrorcode.loader.StdErrorCodeLoader;
import com.eactive.eai.custom.stderrorcode.mapper.StdErrorCodeMapper;
import com.eactive.eai.data.entity.custom.stderrorcode.StdErrorCode;

@Service
@Transactional
public class StdErrorCodeDAO extends BaseDAO {
	private static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);

	@Autowired
	private StdErrorCodeLoader stdErrorCodeEntityService;

	@Autowired
	private StdErrorCodeMapper stdErrorCodeMapper;

	public HashMap getAllSTDErrorCode() throws DAOException {
		try {
			HashMap groups = new HashMap();
			List<StdErrorCode> services = stdErrorCodeEntityService.findAllByNow();
			logger.info("[ @@ Load STD Error Code Configuration - starting >>>>>>>>>>>>>>>>> ]");
			for (StdErrorCode stdErr : services) {
				StdErrorCodeVO vo = stdErrorCodeMapper.toVo(stdErr);
				groups.put(vo.getErrCd(), vo);
				logger.info("[>>Load STD Error Code vo(" + vo.getErrCd() + ") =" + vo + " ]");
			}
			logger.info("[>>Load STD Error Code Configuration - ended ]");
			return groups;
		} catch (Exception e) {
			throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICPM101"));
		}
	}
}
