<?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::create('event_photobooth_settings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('event_id')->constrained()->cascadeOnDelete();
            $table->boolean('enabled')->default(false);
            $table->string('mode', 16)->default('ftp');
            $table->string('username', 32)->nullable();
            $table->text('password_encrypted')->nullable();
            $table->string('path')->nullable();
            $table->string('status', 32)->default('inactive');
            $table->timestamp('expires_at')->nullable();
            $table->timestamp('last_provisioned_at')->nullable();
            $table->timestamp('last_deprovisioned_at')->nullable();
            $table->timestamp('last_upload_at')->nullable();
            $table->unsignedInteger('uploads_last_24h')->default(0);
            $table->unsignedBigInteger('uploads_total')->default(0);
            $table->json('metadata')->nullable();
            $table->timestamps();

            $table->unique('event_id');
            $table->unique('username');
            $table->index(['enabled', 'expires_at']);
            $table->index(['enabled', 'path']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('event_photobooth_settings');
    }
};
