<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddDonationCategoryToExpenses extends Migration
{
    /**
     * Allow marking expenses as non-reimbursable donations.
     */
    public function up()
    {
        $this->forge->modifyColumn('expenses', [
            'category' => [
                'type' => "ENUM('Expense','Purchase','Reimbursement','Donation')",
                'null' => false,
            ],
        ]);
    }

    /**
     * Revert to the original enum; donation rows are coerced back to Expense.
     */
    public function down()
    {
        // Convert any donation rows to Expense to keep rollback safe.
        $this->db->table('expenses')
            ->where('category', 'Donation')
            ->set('category', 'Expense')
            ->update();

        $this->forge->modifyColumn('expenses', [
            'category' => [
                'type' => "ENUM('Expense','Purchase','Reimbursement')",
                'null' => false,
            ],
        ]);
    }
}
