<?php

use App\Domains\Domain\Actions\VerifyDomain;
use App\Domains\Domain\Models\Domain;

it('reports unverified domain as not verified', function () {
    $domain = Domain::factory()->create([
        'hostname' => 'example.com',
        'verification_token' => 'abc123',
        'verified_at' => null,
    ]);

    expect($domain->isVerified())->toBeFalse();
});

it('reports verified domain as verified', function () {
    $domain = Domain::factory()->create([
        'hostname' => 'example.com',
        'verification_token' => 'abc123',
        'verified_at' => now(),
    ]);

    expect($domain->isVerified())->toBeTrue();
});

it('does not verify domain with wrong TXT record', function () {
    $domain = Domain::factory()->create([
        'hostname' => 'nonexistent-domain-that-will-fail-dns.invalid',
        'verification_token' => 'wrongtoken',
    ]);

    $action = new VerifyDomain;
    $result = $action->handle($domain);

    expect($result)->toBeFalse()
        ->and($domain->fresh()->verified_at)->toBeNull();
});
