<?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('events', function (Blueprint $table) {
            $table->string('photobooth_mode', 16)
                ->default('ftp')
                ->after('photobooth_enabled');

            $table->string('sparkbooth_username', 32)
                ->nullable()
                ->after('photobooth_path');
            $table->text('sparkbooth_password_encrypted')
                ->nullable()
                ->after('sparkbooth_username');
            $table->timestamp('sparkbooth_expires_at')
                ->nullable()
                ->after('sparkbooth_password_encrypted');
            $table->string('sparkbooth_status', 32)
                ->default('inactive')
                ->after('sparkbooth_expires_at');
            $table->timestamp('sparkbooth_last_upload_at')
                ->nullable()
                ->after('sparkbooth_status');
            $table->unsignedInteger('sparkbooth_uploads_last_24h')
                ->default(0)
                ->after('sparkbooth_last_upload_at');
            $table->unsignedBigInteger('sparkbooth_uploads_total')
                ->default(0)
                ->after('sparkbooth_uploads_last_24h');

            $table->unique('sparkbooth_username');
        });
    }

    public function down(): void
    {
        Schema::table('events', function (Blueprint $table) {
            $table->dropUnique(['sparkbooth_username']);

            $table->dropColumn([
                'photobooth_mode',
                'sparkbooth_username',
                'sparkbooth_password_encrypted',
                'sparkbooth_expires_at',
                'sparkbooth_status',
                'sparkbooth_last_upload_at',
                'sparkbooth_uploads_last_24h',
                'sparkbooth_uploads_total',
            ]);
        });
    }
};
