package com.madeu.dao.web.webgroup;

import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import jakarta.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class WebGroupSqlMapDAO extends SqlSessionDaoSupport{

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 조직 조회 (List, option)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListGroupOption(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO selectListGroupOption START");
		String sqlId = "WebGroup.selectListGroupOption";
		logger.debug("WebGroupSqlMapDAO selectListGroupOption END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 조직 정보 총 갯수 조회 (total count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalGroupCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO selectTotalGroupCount START");
		String sqlId = "WebGroup.selectTotalGroupCount";
		logger.debug("WebGroupSqlMapDAO selectTotalGroupCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 조직 정보 리스트 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListGroup(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO selectListGroup START");
		String sqlId = "WebGroup.selectListGroup";
		logger.debug("WebGroupSqlMapDAO selectListGroup END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 조직 정보 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectGroup(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO selectGroup START");
		String sqlId = "WebGroup.selectGroup";
		logger.debug("WebGroupSqlMapDAO selectGroup END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 조직 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertGroup(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO insertGroup START");
		String sqlId = "WebGroup.insertGroup";
		logger.debug("WebGroupSqlMapDAO insertGroup END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 조직 정보 수정
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateGroup(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO updateGroup START");
		String sqlId = "WebGroup.updateGroup";
		logger.debug("WebGroupSqlMapDAO updateGroup END");
		return getSqlSession().update(sqlId, paramMap);
	}
	
	/**
	 * 조직 정보 삭제
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteGroup(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebGroupSqlMapDAO deleteGroup START");
		String sqlId = "WebGroup.deleteGroup";
		logger.debug("WebGroupSqlMapDAO deleteGroup END");
		return getSqlSession().update(sqlId, paramMap);
	}
}
