<?php

declare(strict_types=1);

use App\Support\References\Contracts\ReferenceResolver;
use App\Support\References\ReferenceClass;
use App\Support\References\ReferenceDescriptor;
use App\Support\References\ReferenceResolutionState;
use App\Support\References\ReferenceResolverRegistry;
use App\Support\References\ReferenceTechnicalDetail;
use App\Support\References\ResolvedReference;
use App\Support\References\Resolvers\FallbackReferenceResolver;

it('supports registering additional resolvers without affecting existing ones', function (): void {
    $customResolver = new class implements ReferenceResolver
    {
        public function referenceClass(): ReferenceClass
        {
            return ReferenceClass::ServicePrincipal;
        }

        public function resolve(ReferenceDescriptor $descriptor): ResolvedReference
        {
            return new ResolvedReference(
                referenceClass: $descriptor->referenceClass,
                rawIdentifier: $descriptor->rawIdentifier,
                primaryLabel: 'Automation app',
                secondaryLabel: 'Service principal',
                state: ReferenceResolutionState::Resolved,
                stateLabel: null,
                linkTarget: null,
                technicalDetail: ReferenceTechnicalDetail::forIdentifier($descriptor->rawIdentifier),
            );
        }
    };

    $registry = new ReferenceResolverRegistry(
        resolvers: [$customResolver],
        fallbackResolver: new FallbackReferenceResolver,
    );

    $resolved = $registry->resolve(new ReferenceDescriptor(
        referenceClass: ReferenceClass::ServicePrincipal,
        rawIdentifier: 'spn-1',
    ));

    expect($resolved->primaryLabel)->toBe('Automation app');
});
