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

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for clone and bulk page writes.
 */
final class BatchCompositionAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool, type: string}>
     */
    public static function entries(): array
    {
        return [
            'clone_structure' => [
                'handler'     => 'cloneStructure',
                'slug'        => 'lolacore-bricks/clone-structure',
                'label'       => 'Clone Structure',
                'description' => 'Copy a Bricks element branch onto several pages with new IDs and optional content per page. Call with dry_run first. Twenty pages run in batches until finished is true.',
                'destructive' => false,
                'idempotent'  => false,
                'type'        => 'write',
            ],
            'bulk_update_content' => [
                'handler'     => 'bulkUpdateContent',
                'slug'        => 'lolacore-bricks/bulk-update-content',
                'label'       => 'Bulk Update Content',
                'description' => 'Update text, images, or links on matching elements across several pages. Call with dry_run first. Large sets run in batches until finished is true.',
                'destructive' => false,
                'idempotent'  => true,
                'type'        => 'write',
            ],
            'bulk_apply_classes' => [
                'handler'     => 'bulkApplyClasses',
                'slug'        => 'lolacore-bricks/bulk-apply-classes',
                'label'       => 'Bulk Apply Classes',
                'description' => 'Add or remove Bricks global classes on matching elements across several pages. Call with dry_run first. Large sets run in batches until finished is true.',
                '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' => true,
                '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()
        ));
    }
}
