<?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_default_addresses', function (Blueprint $table) {
            $table->id();
            $table->foreignId('account_id')->constrained('accounts')->cascadeOnDelete();
            $table->foreignId('domain_id')->constrained('domains')->cascadeOnDelete();
            $table->enum('mode', ['discard', 'forward', 'fail', 'local'])->default('fail');
            $table->string('forward_to', 255)->nullable();
            $table->string('fail_message', 500)->nullable();
            $table->foreignId('local_mailbox_id')->nullable()->constrained('email_accounts')->nullOnDelete();
            $table->timestamps();
            $table->unique(['account_id', 'domain_id']);
        });
    }

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