package com.eactive.eai.common.unifbwk;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

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.unifbwk.loader.UnifBwkTpLoader;
import com.eactive.eai.common.unifbwk.mapper.UnifBwkTpMapper;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.data.entity.onl.unifbwk.UnifBwkTp;

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

	@Autowired
	private UnifBwkTpLoader unifBwkTpLoader;

	@Autowired
	private UnifBwkTpMapper unifBwkTpMapper;

	public List<UnifBwkTpVO> getAllUnifBwkTp() throws DAOException {
		try {
			List<UnifBwkTp> list = unifBwkTpLoader.findAll();
			List<UnifBwkTpVO> volist = new ArrayList<>();
			list.forEach(e -> volist.add(unifBwkTpMapper.toVo(e)));
			return volist;
		} catch (Exception e) {
			throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICUB101"));
		}
	}

	public UnifBwkTpVO getUnifBwkTp(String bwkClsCd) throws DAOException {
		try {
			Optional<UnifBwkTp> entity = unifBwkTpLoader.findById(bwkClsCd);
			UnifBwkTpVO vo = null;
			if (entity.isPresent()) {
				vo = unifBwkTpMapper.toVo(entity.get());
			}
			return vo;
		} catch (Exception e) {
			throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICUB103"));
		}
	}
}
