<?php

declare(strict_types=1);

namespace App\Framework\Audit\ValueObjects;

use App\Framework\DateTime\Clock;
use App\Framework\Ulid\Ulid;

/**
 * Audit Entry ID value object (ULID-based)
 */
final readonly class AuditId
{
    private Ulid $ulid;

    public function __construct(
        Clock $clock,
        ?string $value = null
    ) {
        $this->ulid = $value !== null
            ? Ulid::fromString($clock, $value)
            : new Ulid($clock);
    }

    public static function generate(Clock $clock): self
    {
        return new self($clock);
    }

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

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

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

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