<?php

use App\Support\AdminPermissionBridge;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

test('normalizeCanonicalLegacySlugs maps deprecated audit and report slugs', function (): void {
    $normalized = AdminPermissionBridge::normalizeCanonicalLegacySlugs([
        'prd.audit.finance',
        'prd.report.player',
        'prd.users.manage',
    ]);

    expect($normalized)->toBe([
        'prd.audit.view',
        'prd.report.view',
        'prd.users.manage',
    ]);
});

test('legacy permission slugs are derived from role menu actions only', function (): void {
    $role = \App\Models\AdminRole::query()->create([
        'slug' => 'derived_only',
        'name' => 'Derived',
    ]);

    $role->syncLegacyPermissionSlugs(['prd.report.view']);

    expect($role->fresh()->legacyPermissionSlugs())->toBe(['prd.report.view']);
    expect(\Illuminate\Support\Facades\Schema::hasTable('admin_role_legacy_permissions'))->toBeFalse();
});
