<?php

namespace App\Modules\Settings\Rbac\DTOs;

final readonly class TenantUserWriteData
{
    /**
     * @param  list<int>  $roleIds
     */
    public function __construct(
        public string $name,
        public string $email,
        public ?int $employeeId,
        public array $roleIds,
    ) {}

    /**
     * @param  array<string, mixed>  $validated
     */
    public static function fromValidated(array $validated): self
    {
        return new self(
            name: trim((string) $validated['name']),
            email: mb_strtolower(trim((string) $validated['email'])),
            employeeId: ! empty($validated['employee_id'])
                ? (int) $validated['employee_id']
                : null,
            roleIds: array_map('intval', $validated['role_ids'] ?? []),
        );
    }
}
