<?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('mail_profiles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->boolean('active')->default(false);
            $table->string('host');
            $table->unsignedSmallInteger('port');
            $table->enum('encryption', ['ssl', 'tls', 'starttls'])->nullable();
            $table->string('username')->nullable();
            $table->text('encrypted_password');
            $table->string('from_address');
            $table->string('from_name')->nullable();
            $table->string('reply_to_address')->nullable();
            $table->string('reply_to_name')->nullable();
            $table->unsignedSmallInteger('priority')->default(0);
            $table->unsignedInteger('max_daily_quota')->nullable();
            $table->unsignedInteger('emails_sent_today')->default(0);
            $table->timestamp('last_success_at')->nullable();
            $table->timestamp('last_error_at')->nullable();
            $table->text('last_error_message')->nullable();
            $table->foreignId('failover_to_id')->nullable()->constrained('mail_profiles')->nullOnDelete();
            $table->string('test_status')->nullable();
            $table->timestamp('test_checked_at')->nullable();
            $table->timestamps();
        });
    }

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