package com.madeu.dao.web.webhospital;

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

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

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

	/**
	 * 병원 정보 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public List<Map<String, Object>> selectHospital(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebHospitalSqlMapDAO selectHospital START");
		String sqlId = "WebHospital.selectHospital";
		logger.debug("WebHospitalSqlMapDAO selectHospital END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 병원 정보 휴일 조회
	 * 
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public List<Map<String, Object>> selectHospitalWeek(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebHospitalSqlMapDAO selectHospitalWeek START");
		String sqlId = "WebHospital.selectHospitalWeek";
		logger.debug("WebHospitalSqlMapDAO selectHospitalWeek END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 병원 정보 휴일 조회2
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public List<Map<String, Object>> selectHospitalWeek2(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebHospitalSqlMapDAO selectHospitalWeek2 START");
		String sqlId = "WebHospital.selectHospitalWeek2";
		logger.debug("WebHospitalSqlMapDAO selectHospitalWeek2 END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 병원 월별 휴일 정보
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public List<Map<String, Object>> selectHospitalHoliday(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebHospitalSqlMapDAO selectHospitalHoliday START");
		String sqlId = "WebHospital.selectHospitalHoliday";
		logger.debug("WebHospitalSqlMapDAO selectHospitalHoliday END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 병원 정보 수정
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateHospital(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebHospitalSqlMapDAO updateHospital START");
		String sqlId = "WebHospital.updateHospital";
		logger.debug("WebHospitalSqlMapDAO updateHospital END");
		return getSqlSession().update(sqlId, paramMap);
	}

	/**
	 * 병원 스케줄 상세 조회
	 */
	public Map<String, Object> selectHospitalScheduleDetail(HashMap<String, Object> paramMap)
			throws DataAccessException {
		return getSqlSession().selectOne("WebHospital.selectHospitalScheduleDetail", paramMap);
	}

	/**
	 * 병원 스케줄 존재 여부 확인
	 */
	public Map<String, Object> selectHospitalScheduleCheck(HashMap<String, Object> paramMap)
			throws DataAccessException {
		return getSqlSession().selectOne("WebHospital.selectHospitalScheduleCheck", paramMap);
	}

	/**
	 * 병원 휴일 여부 확인 (스케줄 등록되지 않은 날짜 기준)
	 */
	public Map<String, Object> selectHospitalHolidayCheck(HashMap<String, Object> paramMap)
			throws DataAccessException {
		return getSqlSession().selectOne("WebHospital.selectHospitalHolidayCheck", paramMap);
	}

	/**
	 * 병원 스케줄 등록
	 */
	public int insertHospitalSchedule(HashMap<String, Object> paramMap) throws DataAccessException {
		return getSqlSession().insert("WebHospital.insertHospitalSchedule", paramMap);
	}

	/**
	 * 병원 스케줄 수정
	 */
	public int updateHospitalSchedule(HashMap<String, Object> paramMap) throws DataAccessException {
		return getSqlSession().update("WebHospital.updateHospitalSchedule", paramMap);
	}

	/**
	 * 병원 스케줄 삭제
	 */
	public int deleteHospitalSchedule(HashMap<String, Object> paramMap) throws DataAccessException {
		return getSqlSession().update("WebHospital.deleteHospitalSchedule", paramMap);
	}
}
