<?php

declare(strict_types=1);

use Illuminate\Support\Facades\App;

it('keeps in-scope surfaces free of retired tenant-first and provider-first copy', function (): void {
    $forbiddenCopyByFile = [
        'apps/platform/app/Filament/Pages/ChooseEnvironment.php' => [
            'Choose tenant',
        ],
        'apps/platform/resources/views/filament/pages/choose-environment.blade.php' => [
            'Choose tenant',
            'Select the tenant for your normal active operating context.',
            'No tenant selected is still a valid workspace state',
            'No active tenants available',
            'View managed tenants',
            'Add tenant',
        ],
        'apps/platform/app/Filament/Pages/Workspaces/ManagedEnvironmentsLanding.php' => [
            'Managed tenants',
        ],
        'apps/platform/resources/views/filament/pages/workspaces/managed-environments-landing.blade.php' => [
            'No managed tenants yet',
            'Choose tenant',
            'Add tenant',
            'Connect your first Microsoft Entra tenant',
        ],
        'apps/platform/resources/views/filament/partials/context-bar.blade.php' => [
            'Tenant scope',
            'Select tenant',
            'Selected tenant',
            'Switch tenant',
            'Clear tenant scope',
            'No active tenants',
            'View managed tenants',
            'Search tenants',
        ],
        'apps/platform/app/Support/OperateHub/OperateHubShell.php' => [
            'ManagedEnvironment scope',
            'All tenants',
        ],
        'apps/platform/app/Filament/Pages/Monitoring/Operations.php' => [
            'Show all tenants',
            'one tenant inside the active workspace',
            'all entitled tenants',
            'tenant-specific context',
        ],
        'apps/platform/app/Filament/Pages/Monitoring/FindingExceptionsQueue.php' => [
            'View tenant register',
            'Open tenant detail',
        ],
        'apps/platform/app/Filament/Pages/Findings/MyFindingsInbox.php' => [
            'Clear tenant filter',
            'No assigned findings match this tenant scope',
            'Open tenant findings',
            'Choose a tenant',
        ],
        'apps/platform/app/Filament/Resources/BackupScheduleResource.php' => [
            'No tenant selected',
        ],
        'apps/platform/app/Filament/Resources/BaselineProfileResource/RelationManagers/BaselineTenantAssignmentsRelationManager.php' => [
            'Remove tenant assignment',
            'No tenants assigned',
        ],
        'apps/platform/resources/views/filament/pages/baseline-compare-landing.blade.php' => [
            'tenant landing',
        ],
        'apps/platform/resources/views/filament/pages/baseline-compare-matrix.blade.php' => [
            'Open tenant compare',
            'Visible tenants',
            'Assigned tenants',
            'Compact unlocks at one visible tenant',
            'Dense multi-tenant scan',
            'No assigned tenants',
            'No visible assigned tenants',
        ],
        'apps/platform/app/Filament/Pages/BaselineCompareMatrix.php' => [
            'Compare assigned tenants',
            'tenant-owned baseline compare',
            'comparing assigned tenants',
            'No visible assigned tenants',
            'visible tenant before compare',
        ],
        'apps/platform/app/Filament/Resources/BaselineProfileResource/Pages/ViewBaselineProfile.php' => [
            'Compare assigned tenants',
            'tenant-owned baseline compare',
            'comparing assigned tenants',
            'No visible assigned tenants',
        ],
        'apps/platform/app/Support/ReasonTranslation/ReasonTranslator.php' => [
            'assigned tenant with compare',
            'access to an assigned tenant',
        ],
        'apps/platform/resources/views/filament/pages/monitoring/finding-exceptions-queue.blade.php' => [
            'Open tenant detail',
            'tenant drilldowns',
        ],
        'apps/platform/resources/views/filament/pages/environment-required-permissions.blade.php' => [
            'No tenant selected',
        ],
        'apps/platform/lang/en/localization.php' => [
            'build this tenant\'s policy inventory',
            'Tenant scope',
            'Select tenant',
            'No tenant selected',
            'No active tenants',
            'Tenant dashboard',
            'tenant blocker',
        ],
        'apps/platform/app/Support/Baselines/BaselineCompareSummaryAssessor.php' => [
            'This tenant does not have an assigned baseline yet.',
        ],
        'apps/platform/app/Support/Baselines/BaselineCompareStats.php' => [
            'This tenant has no baseline assignment. A workspace manager can assign a baseline profile to this tenant.',
            'No tenant selected.',
        ],
        'apps/platform/app/Services/Tenants/TenantActionPolicySurface.php' => [
            'Add tenant',
            'Restore tenant',
            'Archive tenant',
        ],
        'apps/platform/app/Support/Ui/GovernanceActions/GovernanceActionCatalog.php' => [
            'Restore tenant',
            'Archive tenant',
        ],
    ];

    foreach ($forbiddenCopyByFile as $relativePath => $forbiddenStrings) {
        $absolutePath = repo_path($relativePath);

        expect(is_file($absolutePath))->toBeTrue("Expected file [{$relativePath}] to exist for the copy guard.");

        $contents = (string) file_get_contents($absolutePath);

        foreach ($forbiddenStrings as $forbiddenString) {
            expect($contents)
                ->not->toContain($forbiddenString, "Found retired copy [{$forbiddenString}] in [{$relativePath}].");
        }
    }
});

it('keeps auth-provider wording explicitly Microsoft-owned', function (): void {
    App::setLocale('en');

    expect(__('localization.auth.sign_in_microsoft'))->toBe('Sign in with Microsoft')
        ->and(__('localization.policy.common.source_microsoft_intune'))->toBe('Source: Microsoft Intune');
});
