package jumapacelaya.gob.mx.appmovcom.repositorio;

import jakarta.inject.Singleton;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import io.micronaut.transaction.annotation.ReadOnly;

@Singleton
public class AppMovComRepositorio {

    /*private final DataSource dataSource;

    public AppMovComRepositorio(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @ReadOnly
    public boolean validarReferencia(String referencia) {
        String sql = """
            select decode(count(*), 1, 'TRUE', 'FALSE') AS VALIDACION
            from facturacomenc
            wwhere predioid = substr(?, 22, 8)
            and faccomencid = substr(?, 5, 8)
        """;

        try (Connection conn = dataSource.getConnection();
            PreparedStatement stmt = conn.prepareStatement(sql)) {

            stmt.setString(1, referencia);
            stmt.setString(2, referencia);

            ResultSet rs = stmt.executeQuery();
            if (rs.next()) {
                return "TRUE".equalsIgnoreCase(rs.getString("VALIDACION"));
            }
        } catch (Exception e) {
            throw new RuntimeException("Error al validar la referencia: " + e.getMessage(), e);
        }

        return false;
    }*/

}
