package com.viettel.campaign.repository.impl;

import com.viettel.campaign.repository.CampaignExecuteRepository;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.SQLBuilder;
import com.viettel.campaign.web.dto.ApParamDTO;
import com.viettel.campaign.web.dto.ContactCustResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

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

@Repository
public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {

    private static final Logger logger = LoggerFactory.getLogger(CampaignRepositoryImpl.class);

    @Autowired
    NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @Override
    public List<ApParamDTO> getComboBoxStatus(String companySiteId, String completeType) {
        List<ApParamDTO> list = new ArrayList<>();
        Map<String, String> params = new HashMap<>();
        String sql = SQLBuilder.getSqlQueryById(Constants.SQL_MODULES.MODULE_EXECUTE, "get-combo-connect-status");
        try {
            params.put("p_company_site_id", companySiteId);
            params.put("p_complete_type", completeType);
            list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(ApParamDTO.class));
//            list = namedParameterJdbcTemplate.getJdbcTemplate().query(sql, (PreparedStatementSetter) params, BeanPropertyRowMapper.newInstance(ComboBoxDTO.class));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return list;
    }

    @Override
    public List<ApParamDTO> getComboCampaignType(String companySiteId) {
        List<ApParamDTO> list = new ArrayList<>();
        Map<String, String> params = new HashMap<>();
        String sql = SQLBuilder.getSqlQueryById(Constants.SQL_MODULES.MODULE_EXECUTE, "get-combo-campaign-type");
        try {
            params.put("p_company_site_id", companySiteId);
            list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(ApParamDTO.class));
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return list;
    }

    @Override
    public List<ContactCustResultDTO> getInteractiveResult(CampaignRequestDTO dto) {
        return null;
    }
}
