<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('events', function (Blueprint $table) {
            if (! Schema::hasColumn('events', 'live_show_token')) {
                $table->string('live_show_token', 96)
                    ->nullable()
                    ->after('settings');
                $table->unique('live_show_token', 'events_live_show_token_unique');
            }

            if (! Schema::hasColumn('events', 'live_show_token_rotated_at')) {
                $table->timestamp('live_show_token_rotated_at')
                    ->nullable()
                    ->after('live_show_token');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('events', function (Blueprint $table) {
            if (Schema::hasColumn('events', 'live_show_token')) {
                $table->dropUnique('events_live_show_token_unique');
                $table->dropColumn('live_show_token');
            }

            if (Schema::hasColumn('events', 'live_show_token_rotated_at')) {
                $table->dropColumn('live_show_token_rotated_at');
            }
        });
    }
};
