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.ChannelErrorCodeLoader;
import com.eactive.eai.custom.stderrorcode.mapper.ChannelErrorCodeMapper;
import com.eactive.eai.data.entity.custom.stderrorcode.ChannelErrorCode;

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

	@Autowired
	private ChannelErrorCodeLoader channelErrorCodeEntityService;

	@Autowired
	private ChannelErrorCodeMapper channelErrorCodeMapper;

	public HashMap getAllChannelErrorCode() throws DAOException {
		try {
			HashMap groups = new HashMap();
			List<ChannelErrorCode> services = channelErrorCodeEntityService.findAllByNow();
			logger.info("[ @@ Load Channel Error Code Configuration - starting >>>>>>>>>>>>>>>>> ]");
			for (ChannelErrorCode channelErr : services) {
				ChannelErrorCodeVO vo = channelErrorCodeMapper.toVo(channelErr);
				String key = vo.getErrCd() + "_" + vo.getType();
				groups.put(key, vo);
				logger.info("[>>Load Channel Error Code vo(" + key + ") =" + vo + " ]");
			}
			logger.info("[>>Load Channel Error Code Configuration - ended ]");
			return groups;
		} catch (Exception e) {
			throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICPM101"));
		}
	}
}
