<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // PostgreSQL doesn't always drop the check constraint when changing from enum to string
        // The constraint name was inherited from the old 'notifications' table name.
        DB::statement('ALTER TABLE system_notifications DROP CONSTRAINT IF EXISTS notifications_type_check');
        DB::statement('ALTER TABLE system_notifications DROP CONSTRAINT IF EXISTS system_notifications_type_check');

        Schema::table('system_notifications', function (Blueprint $table) {
            $table->string('type')->default('info')->change();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('system_notifications', function (Blueprint $table) {
            $table->enum('type', ['info', 'warning', 'system'])->default('info')->change();
        });
    }
};
