<?php
/**
 * Template write ability schemas.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks\Schemas;

use LolaCoreForBricks\AbilitiesProvider;

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

        $templateId = [
            'template_id' => [
                'type'        => 'integer',
                'description' => 'Bricks template post ID.',
            ],
        ];

        return [
            'createTemplate' => [
                'description' => 'Create a Bricks template with a type such as header, footer, content, or archive. Optional conditions include a page-count preview. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['create template', 'add header', 'crear plantilla', 'crear cabecera'],
                    'stem'  => ['template', 'header', 'footer', 'plantilla'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, [
                        'title'       => ['type' => 'string'],
                        'type'        => ['type' => 'string'],
                        'status'      => ['type' => 'string'],
                        'entire_site' => ['type' => 'boolean'],
                        'conditions'  => ['type' => 'array', 'items' => ['type' => 'object']],
                    ]),
                    'required'   => ['title', 'type'],
                ],
            ],
            'setTemplateContent' => [
                'description' => 'Write the Bricks element tree of one template area (content, header, or footer). Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['set template content', 'escribir plantilla'],
                    'stem'  => ['template', 'content', 'plantilla'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $templateId, [
                        'area'     => ['type' => 'string'],
                        'elements' => ['type' => 'array', 'items' => ['type' => 'object']],
                    ]),
                    'required'   => ['template_id', 'elements'],
                ],
            ],
            'updateTemplateConditions' => [
                'description' => 'Set where a Bricks template applies. Always previews how many pages would change and names examples. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['template conditions', 'apply header', 'condiciones de plantilla'],
                    'stem'  => ['condition', 'template', 'condicion'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $templateId, [
                        'entire_site' => ['type' => 'boolean'],
                        'conditions'  => ['type' => 'array', 'items' => ['type' => 'object']],
                    ]),
                    'required'   => ['template_id'],
                ],
            ],
            'duplicateTemplate' => [
                'description' => 'Duplicate a Bricks template and assign new IDs to every copied element. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['duplicate template', 'duplicar plantilla'],
                    'stem'  => ['duplicate', 'template', 'duplicar'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $templateId),
                    'required'   => ['template_id'],
                ],
            ],
            'deleteTemplate' => [
                'description' => 'Move a Bricks template to the WordPress trash. This is reversible. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['delete template', 'trash template', 'borrar plantilla'],
                    'stem'  => ['delete', 'trash', 'template'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $templateId),
                    'required'   => ['template_id'],
                ],
            ],
        ];
    }
}
