package com.bytesw.bytebot.etl.jdbc;

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.Map;

@Component
public class ETLResponseJDBCRepository {

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

    public int getLastCorrelativeBySession(Long sessionId) {
        SqlSession session = sqlSessionFactory.openSession();

        try {
            Map<String, Object> params = new HashMap<>();
            params.put("sessionId", sessionId);
            return session.selectOne("com.bytesw.bytebot.dao.jdbc.ETLResponseMapper.getLastCorrelativeBySession", params);
        } finally {
            session.close();
        }
    }
}
