package com.madeu.dao.mobile.mobilelogin;

import jakarta.annotation.PostConstruct;
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.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Repository
public class MobileLoginSqlMapDAO extends SqlSessionDaoSupport{

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

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

	/**
	 * 사용자 SNS 로그인 (one)
	 *
	 *
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> snsLogin(HashMap<String, Object> paramMap)
			throws Exception {
		log.debug("MobileLoginSqlMapDAO snsLogin START");
		String sqlId = "MobileLogin.snsLogin";
		log.debug("MobileLoginSqlMapDAO snsLogin END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

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

	/**
	 * 회원 디바이스 삭제
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int deleteDevice(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("MobileLoginSqlMapDAO deleteDevice START");
		String sqlId = "MobileLogin.deleteDevice";
		logger.debug("MobileLoginSqlMapDAO deleteDevice END");
		return getSqlSession().update(sqlId, paramMap);
	}
}