<?php

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

/**
 * grn_statuses was the only status lookup table in the app without a `color`
 * column (every other module's statuses live in the shared `statuses` table,
 * which has one) — that's why the GRN status badge was always the default
 * gray, in both the list table and the view page. Backfilling to match the
 * same draft/confirmed/cancelled palette LookupSeeder uses for
 * purchase_order and sales_order (gray/green/red).
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('grn_statuses', function (Blueprint $table) {
            $table->string('color', 30)->nullable()->after('name');
        });

        DB::table('grn_statuses')->where('code', 'draft')->update(['color' => 'gray']);
        DB::table('grn_statuses')->where('code', 'confirmed')->update(['color' => 'green']);
        DB::table('grn_statuses')->where('code', 'deleted')->update(['color' => 'red']);
    }

    public function down(): void
    {
        Schema::table('grn_statuses', function (Blueprint $table) {
            $table->dropColumn('color');
        });
    }
};
