<?php

use App\Models\Mailbox;
use App\Services\Mail\MailPurpose;
use App\Services\Secrets\SecretVault;
use App\Support\Settings;

it('seeds the five mailboxes so the page shows what is expected', function () {
    // `instance-relay` steht daneben, aus einer eigenen Wanderung: das
    // gemeinsame Versandkonto der KUNDENINSTANZEN, nicht eines der fuenf
    // Absender des Betreibers. Siehe InstanceRelaySeedMigrationTest.
    expect(Mailbox::query()->pluck('key')->sort()->values()->all())
        ->toBe(['billing', 'info', 'instance-relay', 'no-reply', 'office', 'support']);
});

it('marks no-reply as unanswerable and the rest as answerable', function () {
    expect(Mailbox::findByKey('no-reply')->no_reply)->toBeTrue()
        ->and(Mailbox::findByKey('support')->no_reply)->toBeFalse();
});

it('points every purpose at a mailbox, so nothing sends from nowhere', function () {
    // Not just "the setting has a value" — a purpose pointing at a key with
    // no matching row would still pass a not-null check on the setting while
    // MailboxResolver::named() resolves it to nothing and every send throws.
    foreach (MailPurpose::ALL as $purpose) {
        $key = Settings::get(MailPurpose::settingKey($purpose));

        expect($key)->not->toBeNull()
            ->and(Mailbox::findByKey($key))->not->toBeNull();
    }
});

it('no longer offers mail.password as a secret, because it is superseded', function () {
    expect(SecretVault::REGISTRY)->not->toHaveKey('mail.password');
});
