<?php

declare(strict_types=1);

namespace App\Application\LiveComponents;

/**
 * Type-safe state for UserStatsComponent
 *
 * Provides compile-time type safety for user statistics.
 * All properties are readonly and immutable.
 */
final readonly class UserStatsState implements LiveComponentState
{
    public function __construct(
        public ?string $userId = null,
        public ?string $locale = null
    ) {
    }

    /**
     * Create from ComponentData (Framework → Domain conversion)
     */
    public static function fromArray(array $data): self
    {
        return new self(
            userId: $data['userId'] ?? null,
            locale: $data['locale'] ?? null
        );
    }

    /**
     * Create empty state with defaults
     */
    public static function empty(): self
    {
        return new self();
    }

    /**
     * Convert to ComponentData (Domain → Framework conversion)
     */
    public function toArray(): array
    {
        return [
            'userId' => $this->userId,
            'locale' => $this->locale,
        ];
    }
}
