package com.madeu.dao.mobile.mobileuser;

import jakarta.annotation.PostConstruct;
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;

@Repository
public class MobileUserSqlMapDAO extends SqlSessionDaoSupport{
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

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

    /**
     * 고객 확인
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> checkUser(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO checkUser START");
        String sqlId = "MobileUser.checkUser";
        logger.debug("MobileUserSqlMapDAO checkUser END");
        return getSqlSession().selectList(sqlId, paramMap);
    }
    /**
     * 고객 확인
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> checkUser2(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO checkUser2 START");
        String sqlId = "MobileUser.checkUser2";
        logger.debug("MobileUserSqlMapDAO checkUser2 END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

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

    /**
     * 이메일 계정 중복 확인
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectEmailCheck(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO selectEmailCheck START");
        String sqlId = "MobileUser.selectEmailCheck";
        logger.debug("MobileUserSqlMapDAO selectEmailCheck END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

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

    /**
     * 연락처 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public String selectUserPhoneNumber(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO selectUserPhoneNumber START");
        String sqlId = "MobileUser.selectUserPhoneNumber";
        logger.debug("MobileUserSqlMapDAO selectUserPhoneNumber END");
        return getSqlSession().selectOne(sqlId, paramMap);
    }

    /**
     * 기존 비밀번호 확인
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectUserPassword(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO selectUserPassword START");
        String sqlId = "MobileUser.selectUserPassword";
        logger.debug("MobileUserSqlMapDAO selectUserPassword END");
        return getSqlSession().selectList(sqlId, paramMap);
    }


    /**
     * 계정 비밀번호 수정
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int updatePassword(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO updatePassword START");
        String sqlId = "MobileUser.updatePassword";
        logger.debug("MobileUserSqlMapDAO updatePassword END");
        return getSqlSession().update(sqlId, paramMap);
    }

    /**
     * 계정 비밀번호 수정
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int updateUserPassword(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO updateUserPassword START");
        String sqlId = "MobileUser.updateUserPassword";
        logger.debug("MobileUserSqlMapDAO updateUserPassword END");
        return getSqlSession().update(sqlId, paramMap);
    }

    /**
     * 이메일 수정
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int updateEmail(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("MobileUserSqlMapDAO updateEmail START");
        String sqlId = "MobileUser.updateEmail";
        logger.debug("MobileUserSqlMapDAO updateEmail END");
        return getSqlSession().update(sqlId, paramMap);
    }
}
