package com.bytesw.bytebot.jdbc;

import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensBean;
import com.bytesw.bytebot.etl.batch.beans.DeleteDataSensControlBean;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

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

@Component
public class DeleteDataSensJDBCRepository {

    @Autowired
    @Qualifier("sqlSessionFactory")
    private SqlSessionFactory sqlSessionFactory;

    public List<DeleteDataSensBean> getListAgentChannel(String status, String channel){
        SqlSession session = sqlSessionFactory.openSession();
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("status", status);
            params.put("channel", channel);
            return session.selectList("com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getAgentChannel", params);
        } finally {
            session.close();
        }
    }

    public DeleteDataSensBean getAgentChannelByAgentID(String status, String channel, Long id){
        SqlSession session = sqlSessionFactory.openSession();
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("status", status);
            params.put("channel", channel);
            params.put("agentId", id);
            return session.selectOne("com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getAgentChannelByAgentId", params);
        } finally {
            session.close();
        }
    }

    public DeleteDataSensControlBean getControl(Long id){
        SqlSession session = sqlSessionFactory.openSession();
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("agenId", id);
            return session.selectOne("com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getControl", params);
        } finally {
            session.close();
        }
    }

    public List<String> getIntentByAgent(String sensible, Long id){
        SqlSession session = sqlSessionFactory.openSession();
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("sensible", sensible);
            params.put("agenId", id);
            return session.selectList("com.bytesw.bytebot.dao.jdbc.ETLDataSensibleMapper.getIntentByAgent", params);
        } finally {
            session.close();
        }
    }
}
