<?php

declare(strict_types=1);

namespace App\Framework\UserAgent;

/**
 * Value Object representing an unparsed User-Agent string
 * Lightweight, suitable for session storage
 */
final readonly class UserAgent
{
    private function __construct(
        public string $value
    ) {
    }

    /**
     * Factory method - create from string
     */
    public static function fromString(string $userAgentString): self
    {
        return new self($userAgentString);
    }

    /**
     * Parse User-Agent into a rich ParsedUserAgent object
     * Note: Consider injecting UserAgentParser via DI container for better performance
     */
    public function parse(): ParsedUserAgent
    {
        return new UserAgentParser()->parse($this->value);
    }

    /**
     * String representation
     */
    public function __toString(): string
    {
        return $this->value;
    }

    /**
     * Get string representation (explicit method)
     */
    public function toString(): string
    {
        return $this->value;
    }
}
