<?php

declare(strict_types=1);

namespace App\Infrastructure\Api\RapidMail;

final readonly class RecipientListId
{
    private function __construct(
        public int $value
    ) {
        if ($value <= 0) {
            throw new \InvalidArgumentException('RecipientListId must be positive');
        }
    }

    public static function fromInt(int $id): RecipientListId
    {
        return new RecipientListId($id);
    }

    public static function tryFrom(mixed $id): ?RecipientListId
    {
        if (is_int($id)) {
            return new RecipientListId($id);
        }

        return null;
    }

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

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