<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Whether this mailbox logs in before it sends.
 *
 * Distinct from "no password stored yet" — Codex R15#4, P1b. A trusted local
 * or private-network relay legitimately accepts mail with no AUTH at all, and
 * Laravel's own SMTP mailer has always supported that (MAIL_USERNAME/
 * MAIL_PASSWORD simply left unset). Before this column existed, "does not
 * authenticate" and "authenticates, but nobody has typed the password yet"
 * were the same empty password field to Mailbox::isConfigured() and to
 * MailboxTransport — an unauthenticated relay was refused exactly like a
 * genuinely broken one.
 *
 * Defaults true: every mailbox row this table has ever held was either a real
 * SMTP login (the takeover migration only ever wrote a username/password when
 * one existed) or a placeholder awaiting one — true reproduces both cases'
 * actual behaviour unchanged, including for rows that already exist when this
 * migration runs on a live install. The takeover migration is the one place
 * that ever computes false, for the specific relay this column exists to fix.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('mailboxes', function (Blueprint $table) {
            $table->boolean('authenticates')->default(true)->after('password');
        });
    }

    public function down(): void
    {
        Schema::table('mailboxes', function (Blueprint $table) {
            $table->dropColumn('authenticates');
        });
    }
};
