package com.madeu.dao.web.webauth;

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 WebAuthSqlMapDAO extends SqlSessionDaoSupport{

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 권한 조회 (List, option)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListAuthOption(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO selectListAuthOption START");
		String sqlId = "WebAuth.selectListAuthOption";
		logger.debug("WebAuthSqlMapDAO selectListAuthOption END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 권한 정보 총 갯수 조회 (total count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalAuthCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO selectTotalAuthCount START");
		String sqlId = "WebAuth.selectTotalAuthCount";
		logger.debug("WebAuthSqlMapDAO selectTotalAuthCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 권한 정보 리스트 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListAuth(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO selectListAuth START");
		String sqlId = "WebAuth.selectListAuth";
		logger.debug("WebAuthSqlMapDAO selectListAuth END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 권한 정보 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectAuth(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO selectAuth START");
		String sqlId = "WebAuth.selectAuth";
		logger.debug("WebAuthSqlMapDAO selectAuth END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 권한 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertAuth(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO insertAuth START");
		String sqlId = "WebAuth.insertAuth";
		logger.debug("WebAuthSqlMapDAO insertAuth END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	/**
	 * 권한 그룹 정보 수정
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateAuth(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO updateAuth START");
		String sqlId = "WebAuth.updateAuth";
		logger.debug("WebAuthSqlMapDAO updateAuth END");
		return getSqlSession().update(sqlId, paramMap);
	}
	/**
	 * 권한 정보 삭제
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteAuth(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAuthSqlMapDAO deleteAuth START");
		String sqlId = "WebAuth.deleteAuth";
		logger.debug("WebAuthSqlMapDAO deleteAuth END");
		return getSqlSession().update(sqlId, paramMap);
	}
}
