<?php

declare(strict_types=1);

namespace App\Tests\Unit\Shared\Domain;

use App\Shared\Domain\CorrelationId;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid;

final class CorrelationIdTest extends TestCase
{
    public function testGenerateCreatesValidUuid(): void
    {
        $correlationId = CorrelationId::generate();

        $this->assertTrue(Uuid::isValid($correlationId->value()));
    }

    public function testFromStringCreatesCorrelationIdFromValidUuid(): void
    {
        $uuid = '550e8400-e29b-41d4-a716-446655440000';
        $correlationId = CorrelationId::fromString($uuid);

        $this->assertSame($uuid, $correlationId->value());
    }

    public function testValueReturnsUuidString(): void
    {
        $uuid = '550e8400-e29b-41d4-a716-446655440000';
        $correlationId = CorrelationId::fromString($uuid);

        $this->assertSame($uuid, $correlationId->value());
    }

    public function testToStringReturnsUuidString(): void
    {
        $uuid = '550e8400-e29b-41d4-a716-446655440000';
        $correlationId = CorrelationId::fromString($uuid);

        $this->assertSame($uuid, (string) $correlationId);
    }

    public function testGenerateCreatesDifferentIdsEachTime(): void
    {
        $id1 = CorrelationId::generate();
        $id2 = CorrelationId::generate();

        $this->assertNotSame($id1->value(), $id2->value());
    }

    public function testFromStringRejectsInvalidUuid(): void
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Invalid correlation ID format');

        CorrelationId::fromString('not-a-valid-uuid');
    }

    public function testFromStringRejectsEmptyString(): void
    {
        $this->expectException(InvalidArgumentException::class);

        CorrelationId::fromString('');
    }
}
