<?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
    {
        if (Schema::hasTable('email_send_events')) {
            return;
        }

        Schema::create('email_send_events', function (Blueprint $table): void {
            $table->id();
            $table->string('type', 64);
            $table->string('email');
            $table->string('ip', 45)->nullable();
            $table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->string('status', 32);
            $table->string('reason', 64)->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->index('email');
            $table->index('ip');
            $table->index(['type', 'status']);
            $table->index('created_at');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('email_send_events');
    }
};
