<?php
/**
 * Canonical map for B13 page-behavior abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for page settings, conditions, interactions, and dynamic data.
 */
final class PageBehaviorAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool, type: string}>
     */
    public static function entries(): array
    {
        return [
            'update_page_settings' => [
                'handler'     => 'updatePageSettings',
                'slug'        => 'lolacore-bricks/update-page-settings',
                'label'       => 'Update Page Settings',
                'description' => 'Edit Bricks page settings such as SEO, layout, and page CSS. Template conditions stay on the template. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'write',
            ],
            'set_element_conditions' => [
                'handler'     => 'setElementConditions',
                'slug'        => 'lolacore-bricks/set-element-conditions',
                'label'       => 'Set Element Conditions',
                'description' => 'Set when a Bricks element is shown. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'write',
            ],
            'set_element_interactions' => [
                'handler'     => 'setElementInteractions',
                'slug'        => 'lolacore-bricks/set-element-interactions',
                'label'       => 'Set Element Interactions',
                'description' => 'Set Bricks element interactions. Custom JavaScript is rejected. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'write',
            ],
            'list_dynamic_data_tags' => [
                'handler'     => 'listDynamicDataTags',
                'slug'        => 'lolacore-bricks/list-dynamic-data-tags',
                'label'       => 'List Dynamic Data Tags',
                'description' => 'List Bricks dynamic data tags grouped by provider, including ACF when it is active.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'read',
            ],
            'set_dynamic_content' => [
                'handler'     => 'setDynamicContent',
                'slug'        => 'lolacore-bricks/set-dynamic-content',
                'label'       => 'Set Dynamic Content',
                'description' => 'Assign a discovered Bricks dynamic data tag to an element setting. Unknown tags are rejected. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'write',
            ],
        ];
    }

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

        return $actions;
    }

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