<?php

declare(strict_types=1);

namespace App\Administration\Domain\Event;

use App\Shared\Domain\DomainEvent;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/**
 * Event emitted when a login attempt fails.
 *
 * Note: The email is recorded for tracking but does not reveal
 * whether the account exists (same error message in all cases).
 *
 * @see Story 1.4 - AC2: Authentication error handling
 */
final readonly class ConnexionEchouee implements DomainEvent
{
    public function __construct(
        public string $email,
        public ?TenantId $tenantId,
        public string $ipAddress,
        public string $userAgent,
        public string $reason, // 'invalid_credentials', 'account_locked', 'rate_limited'
        public DateTimeImmutable $occurredOn,
    ) {
    }

    public function occurredOn(): DateTimeImmutable
    {
        return $this->occurredOn;
    }

    public function aggregateId(): UuidInterface
    {
        // No associated aggregate, use a UUID based on the email
        return Uuid::uuid5(
            Uuid::NAMESPACE_DNS,
            'login_attempt:' . $this->email,
        );
    }
}
