<?php
/**
 * Canonical map for B10 content shortcut abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for content and add* action metadata.
 */
final class ContentShortcutAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool}>
     */
    public static function entries(): array
    {
        return [
            'set_element_content' => [
                'handler'     => 'setElementContent',
                'slug'        => 'lolacore-bricks/set-element-content',
                'label'       => 'Set Element Content',
                'description' => 'Update text, image, or link content on one or more existing Bricks elements. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
            ],
            'add_section' => [
                'handler'     => 'addSection',
                'slug'        => 'lolacore-bricks/add-section',
                'label'       => 'Add Section',
                'description' => 'Insert a Bricks section with optional content and site classes in one call. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'add_container' => [
                'handler'     => 'addContainer',
                'slug'        => 'lolacore-bricks/add-container',
                'label'       => 'Add Container',
                'description' => 'Insert a Bricks container with optional content and site classes in one call. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'add_div' => [
                'handler'     => 'addDiv',
                'slug'        => 'lolacore-bricks/add-div',
                'label'       => 'Add Div',
                'description' => 'Insert a Bricks div with optional content and site classes in one call. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'add_heading' => [
                'handler'     => 'addHeading',
                'slug'        => 'lolacore-bricks/add-heading',
                'label'       => 'Add Heading',
                'description' => 'Insert a Bricks heading with its text and site classes already set. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'add_text' => [
                'handler'     => 'addText',
                'slug'        => 'lolacore-bricks/add-text',
                'label'       => 'Add Text',
                'description' => 'Insert a Bricks text element with its copy and site classes already set. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'add_image' => [
                'handler'     => 'addImage',
                'slug'        => 'lolacore-bricks/add-image',
                'label'       => 'Add Image',
                'description' => 'Insert a Bricks image from the media library. External URLs are rejected. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'add_button' => [
                'handler'     => 'addButton',
                'slug'        => 'lolacore-bricks/add-button',
                'label'       => 'Add Button',
                'description' => 'Insert a Bricks button with its label, link, and site classes already set. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
        ];
    }

    /**
     * @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' => true,
                'type'                  => 'write',
            ];
        }

        return $actions;
    }

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