import { getDb } from "../backend/src/config/db.js";

async function migrate() {
  const db = getDb();
  try {
    console.log("Checking transactions table...");
    const [columns] = await db.execute("SHOW COLUMNS FROM transactions LIKE 'rejection_note'");
    
    if (columns.length === 0) {
      console.log("Adding rejection_note column...");
      await db.execute("ALTER TABLE transactions ADD COLUMN rejection_note TEXT NULL AFTER status");
    }

    console.log("Updating status enum...");
    // Note: We include 'returned' in the enum
    await db.execute("ALTER TABLE transactions MODIFY COLUMN status ENUM('pending', 'paid', 'completed', 'returned') NOT NULL DEFAULT 'pending'");
    
    console.log("Migration successful!");
    process.exit(0);
  } catch (err) {
    console.error("Migration failed:", err);
    process.exit(1);
  }
}

migrate();
