package com.madeu.dao.web.webpayment;

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 WebPaymentSqlMapDAO  extends SqlSessionDaoSupport {
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @PostConstruct
    void init() {
        setSqlSessionTemplate(sqlSessionTemplate);
    }
    /**
     * 수납 정보 총 갯수 조회 (total count)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectTotalPaymentCount(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectTotalPaymentCount START");
        String sqlId = "WebPayment.selectTotalPaymentCount";
        logger.debug("WebPaymentSqlMapDAO selectTotalPaymentCount END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 결제구분별 수납 금액
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectGroupByPayment(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectGroupByPayment START");
        String sqlId = "WebPayment.selectGroupByPayment";
        logger.debug("WebPaymentSqlMapDAO selectGroupByPayment END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 멤버십결제 수납 금액
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectGroupByMembership(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectGroupByMembership START");
        String sqlId = "WebPayment.selectGroupByMembership";
        logger.debug("WebPaymentSqlMapDAO selectGroupByMembership END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 미수납 종류별 수납 금액
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectCancelByPayment(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectCancelByPayment START");
        String sqlId = "WebPayment.selectCancelByPayment";
        logger.debug("WebPaymentSqlMapDAO selectCancelByPayment END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 진료유형별 수납 금액
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectGroupByTreatment(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectGroupByTreatment START");
        String sqlId = "WebPayment.selectGroupByTreatment";
        logger.debug("WebPaymentSqlMapDAO selectGroupByTreatment END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 수납 정보 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListPayment(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectListPayment START");
        String sqlId = "WebPayment.selectListPayment";
        logger.debug("WebPaymentSqlMapDAO selectListPayment END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 수납 총 금액 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public Map<String, Object> selectTotalAmount(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectTotalAmount START");
        String sqlId = "WebPayment.selectTotalAmount";
        logger.debug("WebPaymentSqlMapDAO selectTotalAmount END");
        return getSqlSession().selectOne(sqlId, paramMap);
    }

    /**
     * 수납내역 리스트 조회 (List, Excel)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectPaymentListExcel(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectPaymentListExcel START");
        String sqlId = "WebPayment.selectPaymentListExcel";
        logger.debug("WebPaymentSqlMapDAO selectPaymentListExcel END");
        return getSqlSession().selectList(sqlId, paramMap);
    }
    
    /**
     * 고객 수납내역 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListPaymentUser(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectListPaymentUser START");
        String sqlId = "WebPayment.selectListPaymentUser";
        logger.debug("WebPaymentSqlMapDAO selectListPaymentUser END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 고객 수납내역 -수납항목 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListPaymentProcedureDetail(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectListPaymentProcedureDetail START");
        String sqlId = "WebPayment.selectListPaymentProcedureDetail";
        logger.debug("WebPaymentSqlMapDAO selectListPaymentProcedureDetail END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 고객 수납내역 -결제항목 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListPaymentDetail(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectListPaymentDetail START");
        String sqlId = "WebPayment.selectListPaymentDetail";
        logger.debug("WebPaymentSqlMapDAO selectListPaymentDetail END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 고객 - 수납 내역 정보 총 갯수 조회 (total count)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectTotalPaymentUser2Count(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectTotalPaymentUser2Count START");
        String sqlId = "WebPayment.selectTotalPaymentUser2Count";
        logger.debug("WebPaymentSqlMapDAO selectTotalPaymentUser2Count END");
        return getSqlSession().selectList(sqlId, paramMap);
    }
    
    /**
     * 고객 - 수납 내역 정보 리스트 조회 (List)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListPaymentUser2(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectListPaymentUser2 START");
        String sqlId = "WebPayment.selectListPaymentUser2";
        logger.debug("WebPaymentSqlMapDAO selectListPaymentUser2 END");
        return getSqlSession().selectList(sqlId, paramMap);
    }
    
    /**
     * 고객 - 수납 내역 정보 리스트 조회 (List, Excel)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectListPaymentUser2Excel(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectListPaymentUser2Excel START");
        String sqlId = "WebPayment.selectListPaymentUser2Excel";
        logger.debug("WebPaymentSqlMapDAO selectListPaymentUser2Excel END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 수납내역 단건 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectPayment(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectPayment START");
        String sqlId = "WebPayment.selectPayment";
        logger.debug("WebPaymentSqlMapDAO selectPayment END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 수납내역 결제번호로 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectPaymentPaymentNumber(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectPaymentPaymentNumber START");
        String sqlId = "WebPayment.selectPaymentPaymentNumber";
        logger.debug("WebPaymentSqlMapDAO selectPaymentPaymentNumber END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 수납상세내역 단건 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectPaymentDetail(String muPaymentId)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectPaymentDetail START");
        String sqlId = "WebPayment.selectPaymentDetail";
        logger.debug("WebPaymentSqlMapDAO selectPaymentDetail END");
        return getSqlSession().selectList(sqlId, muPaymentId);
    }

    /**
     * 수납내역 상태값 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectPaymentStatusCheck(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectPaymentStatusCheck START");
        String sqlId = "WebPayment.selectPaymentStatusCheck";
        logger.debug("WebPaymentSqlMapDAO selectPaymentStatusCheck END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 결제번호 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectPaymentNumber(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectPaymentNumber START");
        String sqlId = "WebPayment.selectPaymentNumber";
        logger.debug("WebPaymentSqlMapDAO selectPaymentNumber END");
        return getSqlSession().selectList(sqlId, paramMap);
    }

    /**
     * 예약번호 조회
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public List<Map<String, Object>> selectReserveId(String muPaymentId)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO selectReserveId START");
        String sqlId = "WebPayment.selectReserveId";
        logger.debug("WebPaymentSqlMapDAO selectReserveId END");
        return getSqlSession().selectList(sqlId, muPaymentId);
    }

	/**
	 * 기존 db 예약 중복 확인
	 *
	 * @param Map
	 * @return
	 * @throws DataAccessException
	 */
	public List<Map<String, Object>> selectListPaymentCheck(HashMap<String, Object> paramMap)
			throws DataAccessException {
		logger.debug("WebPaymentSqlMapDAO selectListPaymentCheck START");
		String sqlId = "WebPayment.selectListPaymentCheck";
		logger.debug("WebPaymentSqlMapDAO selectListPaymentCheck END");
		return getSqlSession().selectList(sqlId, paramMap);
	}

    /**
     * 결제 정보 등록
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertPayment(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO insertPayment START");
        String sqlId = "WebPayment.insertPayment";
        logger.debug("WebPaymentSqlMapDAO insertPayment END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 결제 정보 등록 (배치)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertPaymentBatch(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO insertPaymentBatch START");
        String sqlId = "WebPayment.insertPaymentBatch";
        logger.debug("WebPaymentSqlMapDAO insertPaymentBatch END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 단말기 결제 요청 정보 등록
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertPaymentRequestHistory(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO insertPaymentRequestHistory START");
        String sqlId = "WebPayment.insertPaymentRequestHistory";
        logger.debug("WebPaymentSqlMapDAO insertPaymentRequestHistory END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 단말기 결제 응답 정보 등록
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertPaymentResponseHistory(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO insertPaymentResponseHistory START");
        String sqlId = "WebPayment.insertPaymentResponseHistory";
        logger.debug("WebPaymentSqlMapDAO insertPaymentResponseHistory END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 결제 상세정보 등록
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertPaymentDetail(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO insertPaymentDetail START");
        String sqlId = "WebPayment.insertPaymentDetail";
        logger.debug("WebPaymentSqlMapDAO insertPaymentDetail END");
        return getSqlSession().insert(sqlId, paramMap);
    }

    /**
     * 결제 상세정보 등록 (배치)
     *
     * @param Map
     * @return
     * @throws DataAccessException
     */
    public int insertPaymentDetailBatch(HashMap<String, Object> paramMap)
            throws DataAccessException {
        logger.debug("WebPaymentSqlMapDAO insertPaymentDetailBatch START");
        String sqlId = "WebPayment.insertPaymentDetailBatch";
        logger.debug("WebPaymentSqlMapDAO insertPaymentDetailBatch END");
        return getSqlSession().insert(sqlId, paramMap);
    }

}
