package com.madeu.dao.mobile.mobilejoin;

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

	@Autowired
	private SqlSessionTemplate sqlSessionTemplate;

	@PostConstruct
	void init() {
		setSqlSessionTemplate(sqlSessionTemplate);
	}
	
	/**
	 * 로그인 아이디 중복 체크 (아이디 중복확인)
	 * 
	 * @param Map
	 * @return
	 * @throws Exception 
	 */
	public List<Map<String, Object>> checkMembershipId(HashMap<String, Object> paramMap)
			throws Exception {
		log.debug("MobileJoinSqlMapDAO checkMembershipId START");
		String sqlId = "MobileJoin.checkMembershipId";
		log.debug("MobileJoinSqlMapDAO checkMembershipId END");
		return getSqlSession().selectList(sqlId, paramMap);
	}
	/**
	 * 기존 회원 확인
	 *
	 * @param Map
	 * @return
	 * @throws Exception
	 */
	public List<Map<String, Object>> selectUserInfo(HashMap<String, Object> paramMap)
			throws Exception {
		log.debug("MobileJoinSqlMapDAO selectUserInfo START");
		String sqlId = "MobileJoin.selectUserInfo";
		log.debug("MobileJoinSqlMapDAO selectUserInfo END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

	/**
	 * 기존고객 앱 가입
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int updateUserInfo(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("MobileJoinSqlMapDAO updateUserInfo START");
		String sqlId = "MobileJoin.updateUserInfo";
		logger.debug("MobileJoinSqlMapDAO updateUserInfo END");
		return getSqlSession().update(sqlId, paramMap);
	}

	/**
	 * 신규고객 앱 가입
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public int insertUser(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("MobileJoinSqlMapDAO insertUser START");
		String sqlId = "MobileJoin.insertUser";
		logger.debug("MobileJoinSqlMapDAO insertUser END");
		return getSqlSession().update(sqlId, paramMap);
	}
}