<?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('newsletter_subscribers', function (Blueprint $table) {
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_unicode_ci';
            $table->id();
            $table->string('email', 190);
            $table->string('locale', 5)->default('en');
            $table->string('source_page')->nullable();
            $table->string('source_url', 1024)->nullable();
            $table->string('ip_address', 45)->nullable();
            $table->text('user_agent')->nullable();
            $table->timestamp('created_at')->useCurrent();

            $table->unique('email', 'newsletter_subscribers_email_unique');
            $table->index('locale', 'newsletter_subscribers_locale_index');
            $table->index('created_at', 'newsletter_subscribers_created_at_index');
        });
    }

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