/**
 * Adds "Closed" (status_id 4) to tickets_status so closing a ticket works.
 * Your DB: 1=Open, 2=In Progress, 3=Resolved. This adds 4=Closed.
 * Run from SAT_backend: node run-ticket-status-closed.js
 */
require('dotenv').config();
const mysql = require('mysql2/promise');

async function run() {
  let connection;
  try {
    connection = await mysql.createConnection({
      host: process.env.MYSQL_HOST,
      user: process.env.MYSQL_USER,
      password: process.env.MYSQL_PASSWORD,
      database: "hse"
    });
    await connection.query(
      "INSERT IGNORE INTO tickets_status (status_id, status_type) VALUES (4, 'Closed')"
    );
    const [rows] = await connection.query('SELECT * FROM tickets_status ORDER BY status_id');
    console.log('tickets_status rows:', rows);
    console.log('Closed status (4) is ready. You can close tickets now.');
  } catch (err) {
    console.error('Migration failed:', err.message);
    process.exit(1);
  } finally {
    if (connection) await connection.end();
  }
}

run();
