<?php

declare(strict_types=1);

namespace App\Administration\Application\Command\InviteUser;

use InvalidArgumentException;

use function is_string;

final readonly class InviteUserCommand
{
    /** @var string[] */
    public array $roles;

    /**
     * @param string[] $roles
     */
    public function __construct(
        public string $tenantId,
        public string $schoolName,
        public string $email,
        public string $role,
        public string $firstName,
        public string $lastName,
        public ?string $dateNaissance = null,
        array $roles = [],
    ) {
        $resolved = $roles !== [] ? $roles : [$role];

        foreach ($resolved as $r) {
            if (!is_string($r)) {
                throw new InvalidArgumentException('Chaque rôle doit être une chaîne de caractères.');
            }
        }

        $this->roles = $resolved;
    }
}
