<?php
/**
 * Canonical map for B14 WooCommerce surface abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for shop-template discovery and product-element shortcuts.
 */
final class WooSurfaceAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool, type: string}>
     */
    public static function entries(): array
    {
        return [
            'get_woo_bricks_surface' => [
                'handler'     => 'getWooBricksSurface',
                'slug'        => 'lolacore-bricks/get-woo-bricks-surface',
                'label'       => 'Get Woo Bricks Surface',
                'description' => 'Show which Bricks shop templates exist, which are missing, and which WooCommerce elements the site already uses.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'read',
            ],
            'create_woo_template' => [
                'handler'     => 'createWooTemplate',
                'slug'        => 'lolacore-bricks/create-woo-template',
                'label'       => 'Create Woo Template',
                'description' => 'Create a Bricks shop template for product, archive, cart, checkout, or account, with its conditions already set. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
                'type'        => 'write',
            ],
            'add_product_element' => [
                'handler'     => 'addProductElement',
                'slug'        => 'lolacore-bricks/add-product-element',
                'label'       => 'Add Product Element',
                'description' => 'Insert a WooCommerce product element such as title, price, or gallery. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
                'type'        => 'write',
            ],
            'get_product_elements_catalog' => [
                'handler'     => 'getProductElementsCatalog',
                'slug'        => 'lolacore-bricks/get-product-elements-catalog',
                'label'       => 'Get Product Elements Catalog',
                'description' => 'List Bricks WooCommerce elements grouped by shop function so you can pick one without dumping every name.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'read',
            ],
        ];
    }

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