<?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::create('email_subscribers', function (Blueprint $table) {
            $table->id();
            $table->string('email', 255)->unique();
            $table->string('name', 100)->nullable();
            $table->timestamp('subscribed_at');
            $table->timestamp('unsubscribed_at')->nullable();
            $table->boolean('is_active')->default(false);
            $table->string('ip_address', 45)->nullable();
            $table->string('confirmation_token', 64)->unique();
            $table->timestamp('confirmed_at')->nullable();
            $table->timestamps();

            $table->index('confirmation_token');
            $table->index(['is_active', 'unsubscribed_at']);
        });
    }

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