<?php

use App\Services\Providers\ProviderOperationRegistry;
use App\Support\Providers\Boundary\ProviderBoundaryCatalog;

it('blocks graph request option helpers from platform-core identity resolution seams', function (): void {
    $root = base_path();
    $catalog = app(ProviderBoundaryCatalog::class);
    $seam = $catalog->get('provider.identity_resolution');

    $hits = [];

    foreach ($seam->implementationPaths as $relativePath) {
        if ($relativePath !== 'app/Services/Providers/ProviderIdentityResolution.php') {
            continue;
        }

        $path = $root.'/'.$relativePath;
        $contents = file_get_contents($path);

        if (! is_string($contents)) {
            continue;
        }

        foreach (['graphOptions', 'client_request_id'] as $forbiddenTerm) {
            if (str_contains($contents, $forbiddenTerm)) {
                $hits[] = $relativePath.' contains '.$forbiddenTerm;
            }
        }
    }

    expect($hits)->toBeEmpty('Platform-core identity resolution must not shape Microsoft Graph request options.');
});

it('keeps provider bindings out of platform-core operation definitions', function (): void {
    $registry = app(ProviderOperationRegistry::class);

    foreach ($registry->definitions() as $operationType => $definition) {
        expect($definition)
            ->not->toHaveKey('provider')
            ->not->toHaveKey('binding_status')
            ->not->toHaveKey('handler_notes')
            ->not->toHaveKey('exception_notes');

        expect($registry->bindingFor($operationType, 'microsoft'))->toBeArray();
    }
});
