<?php
/**
 * Canonical map for B5 design-system write abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for variable, palette, and theme style write metadata.
 */
final class DesignSystemAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool}>
     */
    public static function entries(): array
    {
        return [
            'set_global_variable' => [
                'handler'      => 'setGlobalVariable',
                'slug'         => 'lolacore-bricks/set-global-variable',
                'label'        => 'Set Global Variable',
                'description'  => 'Create or update one or more Bricks global variables in a single batch. Warns when a value duplicates another token.',
                'destructive'  => false,
                'idempotent'   => true,
            ],
            'delete_global_variable' => [
                'handler'      => 'deleteGlobalVariable',
                'slug'         => 'lolacore-bricks/delete-global-variable',
                'label'        => 'Delete Global Variable',
                'description'  => 'Remove a Bricks global variable. Call with dry_run first to see where it is referenced.',
                'destructive'  => true,
                'idempotent'   => false,
            ],
            'update_color_palette' => [
                'handler'      => 'updateColorPalette',
                'slug'         => 'lolacore-bricks/update-color-palette',
                'label'        => 'Update Color Palette',
                'description'  => 'Create or update Bricks color palettes and their swatches.',
                'destructive'  => false,
                'idempotent'   => true,
            ],
            'update_theme_style' => [
                'handler'      => 'updateThemeStyle',
                'slug'         => 'lolacore-bricks/update-theme-style',
                'label'        => 'Update Theme Style',
                'description'  => 'Create or update a Bricks theme style, including settings and conditions.',
                'destructive'  => false,
                'idempotent'   => true,
            ],
        ];
    }

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