/**
 * One-time TuneOps status rename to match new UI vocabulary.
 *
 *   old CONFIRMED    → ACKNOWLEDGED   (the active "reviewed, will execute" state)
 *   old ACKNOWLEDGED → DEFERRED       (the parked "seen, not acting now" state)
 *
 * Order matters: the new schema also uses 'ACKNOWLEDGED', so we must vacate the
 * old ACKNOWLEDGED rows (→ DEFERRED) BEFORE promoting CONFIRMED → ACKNOWLEDGED,
 * otherwise the second UPDATE would collide with rows we just want to keep as DEFERRED.
 *
 * Runs exactly once (tracked in _migrations); the runner wraps this in a transaction.
 */
module.exports = {
  name: 'tuneops_status_rename_confirmed_acknowledged',
  up: async (client) => {
    // Step 1 — vacate ACKNOWLEDGED → DEFERRED (must run first).
    await client.query(
      `UPDATE tuneops_tickets SET status = 'DEFERRED' WHERE status = 'ACKNOWLEDGED'`
    );
    // Step 2 — promote CONFIRMED → ACKNOWLEDGED.
    await client.query(
      `UPDATE tuneops_tickets SET status = 'ACKNOWLEDGED' WHERE status = 'CONFIRMED'`
    );
  },
};
