package com.madeu.dao.web.webcompany;

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

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 거래처 정보 콤보 리스트 조회 (List, option)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListCompanyOption(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO selectListCompanyOption START");
		String sqlId = "WebCompany.selectListCompanyOption";
		logger.debug("WebCompanySqlMapDAO selectListCompanyOption END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 거래처 정보 총 갯수 조회 (total count)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectTotalCompanyCount(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO selectTotalCompanyCount START");
		String sqlId = "WebCompany.selectTotalCompanyCount";
		logger.debug("WebCompanySqlMapDAO selectTotalCompanyCount END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 거래처 정보 리스트 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListCompany(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO selectListCompany START");
		String sqlId = "WebCompany.selectListCompany";
		logger.debug("WebCompanySqlMapDAO selectListCompany END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 거래처 정보 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectCompany(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO selectCompany START");
		String sqlId = "WebCompany.selectCompany";
		logger.debug("WebCompanySqlMapDAO selectCompany END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 거래처 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertCompany(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO insertCompany START");
		String sqlId = "WebCompany.insertCompany";
		logger.debug("WebCompanySqlMapDAO insertCompany END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 거래처 정보 수정
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateCompany(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO updateCompany START");
		String sqlId = "WebCompany.updateCompany";
		logger.debug("WebCompanySqlMapDAO updateCompany END");
		return getSqlSession().update(sqlId, paramMap);
	}

	/**
	 * 거래처 정보 삭제
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteCompany(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebCompanySqlMapDAO deleteCompany START");
		String sqlId = "WebCompany.deleteCompany";
		logger.debug("WebCompanySqlMapDAO deleteCompany END");
		return getSqlSession().update(sqlId, paramMap);
	}
}
