<?php

declare(strict_types=1);

namespace App\Administration\Infrastructure\Security;

use App\Administration\Domain\Model\User\Role;
use App\Administration\Domain\Model\User\User as DomainUser;

/**
 * Factory pour créer des SecurityUser depuis des Domain Users.
 *
 * Respecte le principe "No Static" d'Elegant Objects.
 *
 * @see Story 1.4 - Connexion utilisateur
 */
final readonly class SecurityUserFactory
{
    public function fromDomainUser(DomainUser $domainUser): SecurityUser
    {
        return new SecurityUser(
            userId: $domainUser->id,
            email: (string) $domainUser->email,
            hashedPassword: $domainUser->hashedPassword ?? '',
            tenantId: $domainUser->tenantId,
            roles: array_values(array_map(
                static fn (Role $role) => $role->value,
                $domainUser->roles,
            )),
        );
    }
}
