require("dotenv").config();
const { Sequelize } = require("sequelize");

const sequelize = new Sequelize(process.env.DB_DATABASE_SQLSRVTEST, process.env.DB_USERNAME_SQLSRVTEST, process.env.DB_PASSWORD_SQLSRVTEST, {
  host: process.env.DB_HOST_SQLSRVTEST || "localhost",
  port: process.env.DB_PORT_SQLSRVTEST || 1433,
  dialect: "mssql",
  dialectOptions: {
    options: {
      encrypt: false, // Cambia a true se usi SSL
    },
  },
  logging: false, // Disabilita il logging delle query
});

async function testConnection() {
  try {
    await sequelize.authenticate();
    console.log("Connessione al database riuscita!");
  } catch (error) {
    console.error("Errore nella connessione al database:", error);
  }
}

testConnection();

module.exports = sequelize;