package com.madeu.dao.web.weblogin;

import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import jakarta.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Repository
public class WebLoginSqlMapDAO extends SqlSessionDaoSupport{

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 사용자 로그인 (one)
	 * 
	 * 
	 * @param map
	 * @return
	 * @throws Exception 
	 */
	public List<Map<String, Object>> memberLogin(HashMap<String, Object> paramMap)
			throws Exception {
		log.debug("WebLoginSqlMapDAO memberLogin START");
		String sqlId = "WebLogin.memberLogin";
		log.debug("WebLoginSqlMapDAO memberLogin END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 로그인 아이디 중복 체크 (아이디 중복확인)
	 * 
	 * @param Map
	 * @return
	 * @throws Exception 
	 */
	public List<Map<String, Object>> checkloginId(HashMap<String, Object> paramMap)
			throws Exception {
		log.debug("WebLoginSqlMapDAO checkloginId START");
		String sqlId = "WebLogin.checkloginId";
		log.debug("WebLoginSqlMapDAO checkloginId END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 최근 로그인 날짜 갱신
	 *
	 * @param Map
	 * @return
	 * @throws Exception
	 */
	public int updateLastLoginDate(HashMap<String, Object> paramMap)
			throws Exception {
		logger.debug("WebLoginSqlMapDAO updateLastLoginDate START");
		String sqlId = "WebLogin.updateLastLoginDate";
		logger.debug("WebLoginSqlMapDAO updateLastLoginDate END");
		return getSqlSession().update(sqlId, paramMap);
	}

}