package com.madeu.dao.web.webnotice;

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

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 공지사항 정보 총 갯수 조회 (total count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalNoticeCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO selectTotalNoticeCount START");
		String sqlId = "WebNotice.selectTotalNoticeCount";
		logger.debug("WebNoticeSqlMapDAO selectTotalNoticeCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 공지사항 정보 리스트 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListNotice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO selectListNotice START");
		String sqlId = "WebNotice.selectListNotice";
		logger.debug("WebNoticeSqlMapDAO selectListNotice END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 공지사항 정보 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectNotice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO selectNotice START");
		String sqlId = "WebNotice.selectNotice";
		logger.debug("WebNoticeSqlMapDAO selectNotice END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 금일 공지사항 리스트 정보 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListTodayNotice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO selectListTodayNotice START");
		String sqlId = "WebNotice.selectListTodayNotice";
		logger.debug("WebNoticeSqlMapDAO selectListTodayNotice END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 공지사항 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertNotice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO insertNotice START");
		String sqlId = "WebNotice.insertNotice";
		logger.debug("WebNoticeSqlMapDAO insertNotice END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 공지사항 정보 수정
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateNotice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO updateNotice START");
		String sqlId = "WebNotice.updateNotice";
		logger.debug("WebNoticeSqlMapDAO updateNotice END");
		return getSqlSession().update(sqlId, paramMap);
	}

	/**
	 * 공지사항 정보 삭제
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteNotice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebNoticeSqlMapDAO deleteNotice START");
		String sqlId = "WebNotice.deleteNotice";
		logger.debug("WebNoticeSqlMapDAO deleteNotice END");
		return getSqlSession().update(sqlId, paramMap);
	}
}
