<?php

namespace App\Support;

use App\Support\OpsUx\OperationSummaryKeys;

final class OperationCatalog
{
    public const string TYPE_PERMISSION_POSTURE_CHECK = 'permission_posture_check';

    /**
     * @return array<string, string>
     */
    public static function labels(): array
    {
        return [
            'policy.sync' => 'Policy sync',
            'policy.sync_one' => 'Policy sync',
            'policy.capture_snapshot' => 'Policy snapshot',
            'policy.delete' => 'Delete policies',
            'policy.unignore' => 'Restore policies',
            'policy.export' => 'Export policies to backup',
            'provider.connection.check' => 'Provider connection check',
            'inventory_sync' => 'Inventory sync',
            'compliance.snapshot' => 'Compliance snapshot',
            'entra_group_sync' => 'Directory groups sync',
            'backup_set.add_policies' => 'Backup set update',
            'backup_set.remove_policies' => 'Backup set update',
            'backup_set.delete' => 'Archive backup sets',
            'backup_set.restore' => 'Restore backup sets',
            'backup_set.force_delete' => 'Delete backup sets',
            'backup_schedule_run' => 'Backup schedule run',
            'backup_schedule_retention' => 'Backup schedule retention',
            'backup_schedule_purge' => 'Backup schedule purge',
            'restore.execute' => 'Restore execution',
            'assignments.fetch' => 'Assignment fetch',
            'assignments.restore' => 'Assignment restore',
            'ops.reconcile_adapter_runs' => 'Reconcile adapter runs',
            'directory_role_definitions.sync' => 'Role definitions sync',
            'restore_run.delete' => 'Delete restore runs',
            'restore_run.restore' => 'Restore restore runs',
            'restore_run.force_delete' => 'Force delete restore runs',
            'tenant.sync' => 'Tenant sync',
            'policy_version.prune' => 'Prune policy versions',
            'policy_version.restore' => 'Restore policy versions',
            'policy_version.force_delete' => 'Delete policy versions',
            'alerts.evaluate' => 'Alerts evaluation',
            'alerts.deliver' => 'Alerts delivery',
            'baseline_capture' => 'Baseline capture',
            'baseline_compare' => 'Baseline compare',
            'permission_posture_check' => 'Permission posture check',
            'entra.admin_roles.scan' => 'Entra admin roles scan',
            'tenant.review_pack.generate' => 'Review pack generation',
            'rbac.health_check' => 'RBAC health check',
            'findings.lifecycle.backfill' => 'Findings lifecycle backfill',
        ];
    }

    public static function label(string $operationType): string
    {
        $operationType = trim($operationType);

        if ($operationType === '') {
            return 'Operation';
        }

        return self::labels()[$operationType] ?? 'Unknown operation';
    }

    public static function expectedDurationSeconds(string $operationType): ?int
    {
        return match (trim($operationType)) {
            'policy.sync', 'policy.sync_one' => 90,
            'provider.connection.check' => 30,
            'policy.export' => 120,
            'inventory_sync' => 180,
            'compliance.snapshot' => 180,
            'entra_group_sync' => 120,
            'assignments.fetch', 'assignments.restore' => 60,
            'ops.reconcile_adapter_runs' => 120,
            'alerts.evaluate', 'alerts.deliver' => 120,
            'baseline_capture' => 120,
            'baseline_compare' => 120,
            'permission_posture_check' => 30,
            'entra.admin_roles.scan' => 60,
            'tenant.review_pack.generate' => 60,
            'rbac.health_check' => 30,
            'findings.lifecycle.backfill' => 300,
            default => null,
        };
    }

    /**
     * @return array<int, string>
     */
    public static function allowedSummaryKeys(): array
    {
        return OperationSummaryKeys::all();
    }
}
