package com.madeu.dao.web.webappnotice;

import jakarta.annotation.PostConstruct;
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 java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
public class WebAppNoticeSqlMapDAO extends SqlSessionDaoSupport{

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @PostConstruct
    void init() {
        setSqlSessionTemplate(sqlSessionTemplate);
    }

    /**
     * 앱 공지사항 정보 총 갯수 조회 (total count)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectTotalAppNoticeCount(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebAppNoticeSqlMapDAO selectTotalAppNoticeCount START");
        String sqlId = "WebAppNotice.selectTotalAppNoticeCount";
        logger.debug("WebAppNoticeSqlMapDAO selectTotalAppNoticeCount END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 앱 공지사항 정보 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListAppNotice(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebAppNoticeSqlMapDAO selectListAppNotice START");
        String sqlId = "WebAppNotice.selectListAppNotice";
        logger.debug("WebAppNoticeSqlMapDAO selectListAppNotice END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 앱 공지사항 정보 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectAppNotice(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebAppNoticeSqlMapDAO selectAppNotice START");
        String sqlId = "WebAppNotice.selectAppNotice";
        logger.debug("WebAppNoticeSqlMapDAO selectAppNotice END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 앱 공지사항 정보 등록
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertAppNotice(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebAppNoticeSqlMapDAO insertAppNotice START");
        String sqlId = "WebAppNotice.insertAppNotice";
        logger.debug("WebAppNoticeSqlMapDAO insertAppNotice END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 앱 공지사항 정보 수정
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int updateAppNotice(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebAppNoticeSqlMapDAO updateAppNotice START");
        String sqlId = "WebAppNotice.updateAppNotice";
        logger.debug("WebAppNoticeSqlMapDAO updateAppNotice END");
        return getSqlSession().update(sqlId, paramMap);
    }

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

}
