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

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for page-structure action metadata.
 */
final class CompositionAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, type: string, destructive: bool, idempotent: bool}>
     */
    public static function entries(): array
    {
        return [
            'get_page_structure' => [
                'handler'     => 'getPageStructure',
                'slug'        => 'lolacore-bricks/get-page-structure',
                'label'       => 'Get Page Structure',
                'description' => 'Summarize the Bricks element tree for a page area. Expand one branch when you need detail.',
                'type'        => 'read',
                'destructive' => false,
                'idempotent'  => true,
            ],
            'insert_element' => [
                'handler'     => 'insertElement',
                'slug'        => 'lolacore-bricks/insert-element',
                'label'       => 'Insert Element',
                'description' => 'Insert a Bricks element into a page area. Call with dry_run first to preview placement.',
                'type'        => 'write',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'move_element' => [
                'handler'     => 'moveElement',
                'slug'        => 'lolacore-bricks/move-element',
                'label'       => 'Move Element',
                'description' => 'Move a Bricks element to another parent or position. Call with dry_run first to preview the tree.',
                'type'        => 'write',
                'destructive' => false,
                'idempotent'  => true,
            ],
            'duplicate_element' => [
                'handler'     => 'duplicateElement',
                'slug'        => 'lolacore-bricks/duplicate-element',
                'label'       => 'Duplicate Element',
                'description' => 'Duplicate a Bricks element branch with new IDs. Call with dry_run first to preview the copy.',
                'type'        => 'write',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'delete_element' => [
                'handler'     => 'deleteElement',
                'slug'        => 'lolacore-bricks/delete-element',
                'label'       => 'Delete Element',
                'description' => 'Remove a Bricks element branch from a page. Call with dry_run first to review what will be removed.',
                'type'        => 'write',
                'destructive' => true,
                'idempotent'  => false,
            ],
        ];
    }

    /**
     * @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()
        ));
    }
}
