package com.madeu.dao.web.webattendance;

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

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 근태관리 정보 - 조회날짜 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListAttendanceDate(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectListAttendanceDate START");
		String sqlId = "WebAttendance.selectListAttendanceDate";
		logger.debug("WebAttendanceSqlMapDAO selectListAttendanceDate END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 - 직원 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListAttendanceMember(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectListAttendanceMember START");
		String sqlId = "WebAttendance.selectListAttendanceMember";
		logger.debug("WebAttendanceSqlMapDAO selectListAttendanceMember END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 - 날짜별,직원 근태 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListAttendance(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectListAttendance START");
		String sqlId = "WebAttendance.selectListAttendance";
		logger.debug("WebAttendanceSqlMapDAO selectListAttendance END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 - 해당 날짜 등록여부 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectAttendanceDate(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectAttendanceDate START");
		String sqlId = "WebAttendance.selectAttendanceDate";
		logger.debug("WebAttendanceSqlMapDAO selectAttendanceDate END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 상세 정보 조회 (출/퇴근 조회)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectAttendanceCommute(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectAttendanceCommute START");
		String sqlId = "WebAttendance.selectAttendanceCommute";
		logger.debug("WebAttendanceSqlMapDAO selectAttendanceCommute END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 상세 정보 조회 (연차 조회)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectAttendanceVacation(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectAttendanceVacation START");
		String sqlId = "WebAttendance.selectAttendanceVacation";
		logger.debug("WebAttendanceSqlMapDAO selectAttendanceVacation END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 금일 근무현황 정보 조회 (List)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException 
	 */
	public List<Map<String, Object>> selectListTodayAttendance(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO selectListTodayAttendance START");
		String sqlId = "WebAttendance.selectListTodayAttendance";
		logger.debug("WebAttendanceSqlMapDAO selectListTodayAttendance END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 등록
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertAttendance(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO insertAttendance START");
		String sqlId = "WebAttendance.insertAttendance";
		logger.debug("WebAttendanceSqlMapDAO insertAttendance END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 수정 (출/퇴근)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateAttendanceCommute(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO updateAttendanceCommute START");
		String sqlId = "WebAttendance.updateAttendanceCommute";
		logger.debug("WebAttendanceSqlMapDAO updateAttendanceCommute END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 수정 (연차)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateAttendanceVacation(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO updateAttendanceVacation START");
		String sqlId = "WebAttendance.updateAttendanceVacation";
		logger.debug("WebAttendanceSqlMapDAO updateAttendanceVacation END");
		return getSqlSession().insert(sqlId, paramMap);
	}
	
	/**
	 * 근태관리 정보 취소 (연차)
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateAttendanceCancel(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebAttendanceSqlMapDAO updateAttendanceCancel START");
		String sqlId = "WebAttendance.updateAttendanceCancel";
		logger.debug("WebAttendanceSqlMapDAO updateAttendanceCancel END");
		return getSqlSession().insert(sqlId, paramMap);
	}
}
