<?php

declare(strict_types=1);

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use TechnoArtisan\FilamentCms\Database\BaseMigration;
use TechnoArtisan\FilamentCms\Enums\ContactRequest;

return new class extends BaseMigration {
    protected const string TABLE = 'fcms_contact_requests';

    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create(self::TABLE, function (Blueprint $table): void {
            $this->basicTableSetup($table); // engine, charset, collation

            $table->increments('id'); // INT (10) unsigned

            $table->string('name', 255);
            $table->string('email', 255);
            $table->enum('request', ContactRequest::toArray())->default(ContactRequest::OTHER_MISC->value);
            $table->text('message');
            $table->boolean('consent')->default(false);
            $table->string('ip', 64);
            $table->string('user_agent', 2048);

            $table->string('session_id', 255)->nullable();
            $table->mediumText('session_data')->nullable();

            $table->text('answer')->nullable();
            $table->timestamp('answered_at')->nullable();

            $table->timestamps();

            // Indexes
            $table->index('email', 'IDX_email');
            $table->index('session_id', 'IDX_session_id');
        });
    }
};
