package com.madeu.dao.web.webproduct;

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

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

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

	/**
	 * 제품 정보 총 갯수 조회 (total count, option)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalProductOptionCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO selectTotalProductOptionCount START");
		String sqlId = "WebProduct.selectTotalProductOptionCount";
		logger.debug("WebProductSqlMapDAO selectTotalProductOptionCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 제품 정보 리스트 조회 (List, option)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListProductOption(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO selectListProductOption START");
		String sqlId = "WebProduct.selectListProductOption";
		logger.debug("WebProductSqlMapDAO selectListProductOption END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	

	/**
	 * 제품 정보 총 갯수 조회 (total count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalProductCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO selectTotalProductCount START");
		String sqlId = "WebProduct.selectTotalProductCount";
		logger.debug("WebProductSqlMapDAO selectTotalProductCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 제품 정보 리스트 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListProduct(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO selectListProduct START");
		String sqlId = "WebProduct.selectListProduct";
		logger.debug("WebProductSqlMapDAO selectListProduct END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 제품 확인 조회 (one)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> checkProduct(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO checkProduct START");
		String sqlId = "WebProduct.checkProduct";
		logger.debug("WebProductSqlMapDAO checkProduct END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 제품 코드 조회 (one, seq)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectProductCountSeq(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO selectProductCountSeq START");
		String sqlId = "WebProduct.selectProductCountSeq";
		logger.debug("WebProductSqlMapDAO selectProductCountSeq END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 제품 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertProduct(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO insertProduct START");
		String sqlId = "WebProduct.insertProduct";
		logger.debug("WebProductSqlMapDAO insertProduct END");
		return getSqlSession().insert(sqlId, paramMap);
	}

	/**
	 * 제품 정보 삭제
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteProduct(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebProductSqlMapDAO deleteProduct START");
		String sqlId = "WebProduct.deleteProduct";
		logger.debug("WebProductSqlMapDAO deleteProduct END");
		return getSqlSession().update(sqlId, paramMap);
	}

}
