<?php

declare(strict_types=1);

namespace ApiModel\Domain\Entities;

final class User
{
    public function __construct(
        public readonly string $id,
        public readonly string $name,
        public readonly string $email,
        public readonly string $role,
        public readonly string $language = 'es',
    ) {}

    /** @param array<string,mixed> $row */
    public static function fromArray(array $row): self
    {
        return new self(
            (string) $row['id'],
            (string) $row['name'],
            (string) $row['email'],
            (string) $row['role'],
            (string) ($row['language'] ?? 'es'),
        );
    }
}
