<?php

declare(strict_types=1);

namespace App\Framework\Notification\Channels\Telegram\ValueObjects;

/**
 * Telegram Chat ID Value Object
 *
 * Can be:
 * - User chat: numeric (positive or negative)
 * - Group chat: numeric (negative)
 * - Channel: @username or numeric
 */
final readonly class TelegramChatId
{
    public function __construct(
        public string $value
    ) {
        if (empty($value)) {
            throw new \InvalidArgumentException('Telegram chat ID cannot be empty');
        }
    }

    public static function fromString(string $value): self
    {
        return new self($value);
    }

    public static function fromInt(int $value): self
    {
        return new self((string) $value);
    }

    public function isUsername(): bool
    {
        return str_starts_with($this->value, '@');
    }

    public function isNumeric(): bool
    {
        return is_numeric($this->value);
    }

    public function toString(): string
    {
        return $this->value;
    }

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

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }
}
