<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * PRC-404 / C-001 — Extend `invoices.status` enum to include 'proforma'.
 *
 * PRC-371 introduced the `enable_proforma_invoicing` toggle and writes
 * status='proforma' on invoice creation, but the original enum (created
 * by `2024_09_24_125323_create_invoices_table.php`) didn't list
 * 'proforma', so the value was silently truncated to the default
 * 'pending'. Effect: the proforma PDF banner condition never matched.
 *
 * This migration adds 'proforma' to the allowed values. Existing rows
 * are not touched (defaults remain 'pending').
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->enum('status', [
                'pending', 'unpaid', 'paid', 'overdue',
                'cancelled', 'refunded', 'fraud', 'proforma',
            ])->default('pending')->change();
        });
    }

    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->enum('status', [
                'pending', 'unpaid', 'paid', 'overdue',
                'cancelled', 'refunded', 'fraud',
            ])->default('pending')->change();
        });
    }
};
