<?php
/**
 * Canonical map for B2 knowledge abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for knowledge read action metadata.
 */
final class KnowledgeAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string}>
     */
    public static function entries(): array
    {
        return [
            'get_global_classes' => [
                'handler'     => 'getGlobalClasses',
                'slug'        => 'lolacore-bricks/get-global-classes',
                'label'       => 'Get Global Classes',
                'description' => 'List Bricks global classes with categories and lock state.',
            ],
            'get_class_usage' => [
                'handler'     => 'getClassUsage',
                'slug'        => 'lolacore-bricks/get-class-usage',
                'label'       => 'Get Class Usage',
                'description' => 'Show where a global class is used, grouped by page.',
            ],
            'get_global_variables' => [
                'handler'     => 'getGlobalVariables',
                'slug'        => 'lolacore-bricks/get-global-variables',
                'label'       => 'Get Global Variables',
                'description' => 'List Bricks global variables and color palette.',
            ],
            'get_variable_usage' => [
                'handler'     => 'getVariableUsage',
                'slug'        => 'lolacore-bricks/get-variable-usage',
                'label'       => 'Get Variable Usage',
                'description' => 'Show references to a global variable.',
            ],
            'get_theme_styles' => [
                'handler'     => 'getThemeStyles',
                'slug'        => 'lolacore-bricks/get-theme-styles',
                'label'       => 'Get Theme Styles',
                'description' => 'List Bricks theme styles with conditions.',
            ],
            'get_components' => [
                'handler'     => 'getComponents',
                'slug'        => 'lolacore-bricks/get-components',
                'label'       => 'Get Components',
                'description' => 'List Bricks components with instance counts.',
            ],
            'get_component_usage' => [
                'handler'     => 'getComponentUsage',
                'slug'        => 'lolacore-bricks/get-component-usage',
                'label'       => 'Get Component Usage',
                'description' => 'List instances of a Bricks component.',
            ],
            'get_templates' => [
                'handler'     => 'getTemplates',
                'slug'        => 'lolacore-bricks/get-templates',
                'label'       => 'Get Templates',
                'description' => 'List Bricks templates with conditions.',
            ],
            'resolve_template_for_page' => [
                'handler'     => 'resolveTemplateForPage',
                'slug'        => 'lolacore-bricks/resolve-template-for-page',
                'label'       => 'Resolve Template For Page',
                'description' => 'Resolve winning Bricks templates for a page.',
            ],
            'describe_element_controls' => [
                'handler'     => 'describeElementControls',
                'slug'        => 'lolacore-bricks/describe-element-controls',
                'label'       => 'Describe Element Controls',
                'description' => 'Describe Bricks element control contracts.',
            ],
            'get_bricks_operating_guide' => [
                'handler'     => 'getBricksOperatingGuide',
                'slug'        => 'lolacore-bricks/get-bricks-operating-guide',
                'label'       => 'Get Bricks Operating Guide',
                'description' => 'Return Bricks domain SOP and architect guidance.',
            ],
        ];
    }

    /**
     * @return array<string, array{requires_confirmation: bool, type: string}>
     */
    public static function doorTwoActions(): array
    {
        $actions = [];
        foreach (array_keys(self::entries()) as $actionId) {
            $actions[$actionId] = [
                'requires_confirmation' => false,
                'type'                  => 'read',
            ];
        }

        return $actions;
    }

    /**
     * @return string[]
     */
    public static function doorThreeSlugs(): array
    {
        return array_values(array_map(
            static fn (array $entry): string => $entry['slug'],
            self::entries()
        ));
    }
}
