package com.madeu.dao.web.webevent;

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

    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

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

    /**
     * 홈페이지 이벤트 정보 총 갯수 조회 (total count)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectTotalWebEventCount(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebEventSqlMapDAO selectTotalWebEventCount START");
        String sqlId = "WebEvent.selectTotalWebEventCount";
        logger.debug("WebEventSqlMapDAO selectTotalWebEventCount END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 홈페이지 이벤트 정보 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListWebEvent(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebEventSqlMapDAO selectListWebEvent START");
        String sqlId = "WebEvent.selectListWebEvent";
        logger.debug("WebEventSqlMapDAO selectListWebEvent END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 홈페이지 이벤트 정보 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectWebEvent(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebEventSqlMapDAO selectWebEvent START");
        String sqlId = "WebEvent.selectWebEvent";
        logger.debug("WebEventSqlMapDAO selectWebEvent END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 홈페이지 이벤트 정보 등록
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertWebEvent(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebEventSqlMapDAO insertWebEvent START");
        String sqlId = "WebEvent.insertWebEvent";
        logger.debug("WebEventSqlMapDAO insertWebEvent END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 홈페이지 이벤트 정보 수정
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int updateWebEvent(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebEventSqlMapDAO updateWebEvent START");
        String sqlId = "WebEvent.updateWebEvent";
        logger.debug("WebEventSqlMapDAO updateWebEvent END");
        return getSqlSession().update(sqlId, paramMap);
    }

    /**
     * 홈페이지 이벤트 정보 삭제
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int deleteWebEvent(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebEventSqlMapDAO deleteWebEvent START");
        String sqlId = "WebEvent.deleteWebEvent";
        logger.debug("WebEventSqlMapDAO deleteWebEvent END");
        return getSqlSession().update(sqlId, paramMap);
    }

}
