<?php

namespace App\Services\Providers;

use InvalidArgumentException;

final class ProviderOperationRegistry
{
    /**
     * @return array<string, array{provider: string, module: string, label: string}>
     */
    public function all(): array
    {
        return [
            'provider.connection.check' => [
                'provider' => 'microsoft',
                'module' => 'health_check',
                'label' => 'Provider connection check',
            ],
            'inventory.sync' => [
                'provider' => 'microsoft',
                'module' => 'inventory',
                'label' => 'Inventory sync',
            ],
            'compliance.snapshot' => [
                'provider' => 'microsoft',
                'module' => 'compliance',
                'label' => 'Compliance snapshot',
            ],
        ];
    }

    public function isAllowed(string $operationType): bool
    {
        return array_key_exists($operationType, $this->all());
    }

    /**
     * @return array{provider: string, module: string, label: string}
     */
    public function get(string $operationType): array
    {
        $operationType = trim($operationType);

        $definition = $this->all()[$operationType] ?? null;

        if (! is_array($definition)) {
            throw new InvalidArgumentException("Unknown provider operation type: {$operationType}");
        }

        return $definition;
    }
}
