<?php
/**
 * Canonical map for B11 template write abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for template write action metadata.
 */
final class TemplateWriteAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool}>
     */
    public static function entries(): array
    {
        return [
            'create_template' => [
                'handler'     => 'createTemplate',
                'slug'        => 'lolacore-bricks/create-template',
                'label'       => 'Create Template',
                'description' => 'Create a Bricks template with a type such as header, footer, or content. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'set_template_content' => [
                'handler'     => 'setTemplateContent',
                'slug'        => 'lolacore-bricks/set-template-content',
                'label'       => 'Set Template Content',
                'description' => 'Write the element tree of one area on a Bricks template. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
            ],
            'update_template_conditions' => [
                'handler'     => 'updateTemplateConditions',
                'slug'        => 'lolacore-bricks/update-template-conditions',
                'label'       => 'Update Template Conditions',
                'description' => 'Set where a Bricks template applies. Always previews page count and examples. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => true,
            ],
            'duplicate_template' => [
                'handler'     => 'duplicateTemplate',
                'slug'        => 'lolacore-bricks/duplicate-template',
                'label'       => 'Duplicate Template',
                'description' => 'Duplicate a Bricks template and assign new element IDs. Call with dry_run first.',
                'destructive' => false,
                'idempotent'  => false,
            ],
            'delete_template' => [
                'handler'     => 'deleteTemplate',
                'slug'        => 'lolacore-bricks/delete-template',
                'label'       => 'Delete Template',
                'description' => 'Move a Bricks template to the WordPress trash (reversible). 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()
        ));
    }
}
