<?php
/**
 * Design-system write ability schemas.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks\Schemas;

use LolaCoreForBricks\AbilitiesProvider;

/**
 * Door 1 schemas for variable, palette, and theme style writes.
 */
class DesignSystemWriteSchemas
{
    /**
     * @return array<string, array<string, mixed>>
     */
    public static function define(): array
    {
        $dryRun = [
            'dry_run' => [
                'type'        => 'boolean',
                'description' => 'Preview the write without saving changes.',
            ],
        ];

        return [
            'setGlobalVariable' => [
                'description' => 'Create or update Bricks global variables in one batch — ideal for importing a full color palette. Warns when a value duplicates another token.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['set global variable', 'create variable', 'design tokens', 'crear variable'],
                    'stem'  => ['variable', 'token', 'palette'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, [
                        'name'      => ['type' => 'string', 'description' => 'Single variable name when not using variables[].'],
                        'value'     => ['type' => 'string'],
                        'type'      => ['type' => 'string'],
                        'category'  => ['type' => 'string'],
                        'variables' => [
                            'type'        => 'array',
                            'description' => 'Batch of variables to create or update in one confirmation.',
                            'items'       => [
                                'type'       => 'object',
                                'properties' => [
                                    'name'     => ['type' => 'string'],
                                    'value'    => ['type' => 'string'],
                                    'type'     => ['type' => 'string'],
                                    'category' => ['type' => 'string'],
                                ],
                                'required'   => ['name'],
                            ],
                        ],
                    ]),
                ],
            ],
            'deleteGlobalVariable' => [
                'description' => 'Remove a Bricks global variable. Call with dry_run first to see reference counts and affected pages.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['delete global variable', 'remove variable', 'eliminar variable'],
                    'stem'  => ['delete', 'variable'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, [
                        'variable' => ['type' => 'string', 'description' => 'Variable name without the leading --.'],
                    ]),
                    'required'   => ['variable'],
                ],
            ],
            'updateColorPalette' => [
                'description' => 'Create or update Bricks color palettes and their swatches.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['update color palette', 'color palette', 'paleta de color'],
                    'stem'  => ['palette', 'color'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, [
                        'id'     => ['type' => 'string'],
                        'name'   => ['type' => 'string'],
                        'colors' => ['type' => 'array'],
                        'palette' => ['type' => 'object'],
                        'palettes' => ['type' => 'array'],
                    ]),
                ],
            ],
            'updateThemeStyle' => [
                'description' => 'Create or update a Bricks theme style, including settings and conditions.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['update theme style', 'theme style', 'estilo de tema'],
                    'stem'  => ['theme', 'style', 'typography'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, [
                        'style'      => ['type' => 'string', 'description' => 'Theme style id or label.'],
                        'label'      => ['type' => 'string'],
                        'settings'   => ['type' => 'object'],
                        'conditions' => ['type' => 'array'],
                    ]),
                ],
            ],
        ];
    }
}
