<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('sent_reminders', function (Blueprint $table) {
            $table->dropForeign(['event_id']);
            $table->dropUnique(['event_id', 'reminder_hash']);
            $table->uuid('event_id')->nullable()->change();
            $table->string('type')->default('event')->after('reminder_hash');
            $table->unique(['reminder_hash', 'type'], 'sent_reminders_hash_type_unique');
        });

        Schema::table('sent_reminders', function (Blueprint $table) {
            $table->foreign('event_id')->references('id')->on('events')->cascadeOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('sent_reminders', function (Blueprint $table) {
            $table->dropForeign(['event_id']);
            $table->dropUnique('sent_reminders_hash_type_unique');
            $table->dropColumn('type');
            $table->uuid('event_id')->nullable(false)->change();
            $table->unique(['event_id', 'reminder_hash']);
            $table->foreign('event_id')->references('id')->on('events')->cascadeOnDelete();
        });
    }
};
