<?php

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

/**
 * Fix the registration_source enum to include 'public' which is used in code
 * but was missing from the original migration (which had 'website' instead).
 * We keep both 'website' and 'public' for backward compatibility.
 */
return new class extends Migration
{
    public function up(): void
    {
        // MySQL: modify the enum column to include all values used in code
        // We use a raw statement because Laravel's Blueprint doesn't support
        // modifying enum values directly without doctrine/dbal.
        DB::statement("
            ALTER TABLE training_registrations
            MODIFY COLUMN registration_source
            ENUM('website','dashboard','admin','public')
            NOT NULL DEFAULT 'dashboard'
        ");
    }

    public function down(): void
    {
        // Revert to original enum (website, dashboard, admin, public)
        // — already the same, so this is a no-op
        DB::statement("
            ALTER TABLE training_registrations
            MODIFY COLUMN registration_source
            ENUM('website','dashboard','admin','public')
            NOT NULL DEFAULT 'dashboard'
        ");
    }
};
