<?php

declare(strict_types=1);

namespace App\Shared\Domain;

use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

/**
 * @phpstan-consistent-constructor
 */
abstract readonly class EntityId
{
    protected function __construct(
        public UuidInterface $value,
    ) {
    }

    public static function generate(): static
    {
        return new static(Uuid::uuid7());
    }

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

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

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