package com.madeu.dao.mobile.mobiledevice;

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.stereotype.Repository;

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

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

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

    /**
     * 디바이스 정보 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> selectListDevice(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO selectListDevice START");
        String sqlId = "MobileDevice.selectListDevice";
        log.debug("MobileDeviceSqlMapDAO selectListDevice END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 디바이스 정보 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> selectListDevice2(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO selectListDevice2 START");
        String sqlId = "MobileDevice.selectListDevice2";
        log.debug("MobileDeviceSqlMapDAO selectListDevice2 END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 디바이스 정보 조회
     *
     * @param Map
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> selectDevice(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO selectDevice START");
        String sqlId = "MobileDevice.selectDevice";
        log.debug("MobileDeviceSqlMapDAO selectDevice END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 디바이스 푸시 알림 여부 조회
     *
     * @param Map
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> selectDevicePushYn(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO selectDevicePushYn START");
        String sqlId = "MobileDevice.selectDevicePushYn";
        log.debug("MobileDeviceSqlMapDAO selectDevicePushYn END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 디바이스 정보 등록
     *
     * @param Map
     * @return
     * @throws Exception
     */
    public int insertDevice(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO insertDevice START");
        String sqlId = "MobileDevice.insertDevice";
        log.debug("MobileDeviceSqlMapDAO insertDevice END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 디바이스 정보 수정
     *
     * @param map
     * @return
     * @throws Exception
     */
    public int updateDevice(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO updateDevice START");
        String sqlId = "MobileDevice.updateDevice";
        log.debug("MobileDeviceSqlMapDAO updateDevice END");
        return getSqlSession().update(sqlId, paramMap);
    }

    /**
     * 디바이스 정보 수정
     *
     * @param map
     * @return
     * @throws Exception
     */
    public int updateDevicePushYn(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO updateDevicePushYn START");
        String sqlId = "MobileDevice.updateDevicePushYn";
        log.debug("MobileDeviceSqlMapDAO updateDevicePushYn END");
        return getSqlSession().update(sqlId, paramMap);
    }

    /**
     * 디바이스 정보 상태 수정
     *
     * @param map
     * @return
     * @throws Exception
     */
    public int updateDeviceStatus(HashMap<String, Object> paramMap)
            throws Exception {
        log.debug("MobileDeviceSqlMapDAO updateDeviceStatus START");
        String sqlId = "MobileDevice.updateDeviceStatus";
        log.debug("MobileDeviceSqlMapDAO updateDeviceStatus END");
        return getSqlSession().update(sqlId, paramMap);
    }
}
