<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (! Schema::hasTable('collections') || ! Schema::hasColumn('collections', 'moderation_status')) {
            return;
        }

        if (DB::getDriverName() === 'mysql') {
            DB::statement("ALTER TABLE collections MODIFY moderation_status ENUM('active','under_review','restricted','hidden') NOT NULL DEFAULT 'active'");
        }
    }

    public function down(): void
    {
        if (! Schema::hasTable('collections') || ! Schema::hasColumn('collections', 'moderation_status')) {
            return;
        }

        if (DB::getDriverName() === 'mysql') {
            DB::statement("UPDATE collections SET moderation_status = 'active' WHERE moderation_status IN ('under_review', 'restricted')");
            DB::statement("ALTER TABLE collections MODIFY moderation_status ENUM('active','review','hidden') NOT NULL DEFAULT 'active'");
        }
    }
};
