<?php
/**
 * Canonical map for B4 global class write abilities across Doors 2 and 3.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

/**
 * Single registry for global class write action metadata.
 */
final class ClassWriteAbilityMap
{
    /**
     * @return array<string, array{handler: string, slug: string, label: string, description: string, destructive: bool, idempotent: bool}>
     */
    public static function entries(): array
    {
        return [
            'create_global_class' => [
                'handler'      => 'createGlobalClass',
                'slug'         => 'lolacore-bricks/create-global-class',
                'label'        => 'Create Global Class',
                'description'  => 'Create a Bricks global class with name, category, and initial settings.',
                'destructive'  => false,
                'idempotent'   => false,
            ],
            'update_global_class_settings' => [
                'handler'      => 'updateGlobalClassSettings',
                'slug'         => 'lolacore-bricks/update-global-class-settings',
                'label'        => 'Update Global Class Settings',
                'description'  => 'Update Bricks global class settings across breakpoints and states.',
                'destructive'  => false,
                'idempotent'   => true,
            ],
            'rename_global_class' => [
                'handler'      => 'renameGlobalClass',
                'slug'         => 'lolacore-bricks/rename-global-class',
                'label'        => 'Rename Global Class',
                'description'  => 'Rename a Bricks global class. Call with dry_run first to see affected pages and elements.',
                'destructive'  => false,
                'idempotent'   => false,
            ],
            'merge_global_classes' => [
                'handler'      => 'mergeGlobalClasses',
                'slug'         => 'lolacore-bricks/merge-global-classes',
                'label'        => 'Merge Global Classes',
                'description'  => 'Replace one global class with another everywhere and move the source to trash. Call with dry_run first to review impact.',
                'destructive'  => true,
                'idempotent'   => false,
            ],
            'trash_global_classes' => [
                'handler'      => 'trashGlobalClasses',
                'slug'         => 'lolacore-bricks/trash-global-classes',
                'label'        => 'Trash Global Classes',
                'description'  => 'Move Bricks global classes to the native trash (reversible). Call with dry_run first to review impact.',
                'destructive'  => false,
                'idempotent'   => false,
            ],
            'restore_global_class' => [
                'handler'      => 'restoreGlobalClass',
                'slug'         => 'lolacore-bricks/restore-global-class',
                'label'        => 'Restore Global Class',
                'description'  => 'Restore a Bricks global class from the native trash.',
                '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()
        ));
    }
}
