<?php
/**
 * Batch composition ability schemas.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks\Schemas;

use LolaCoreForBricks\AbilitiesProvider;

/**
 * Door 1 schemas for B15 clone and bulk writes.
 */
class BatchCompositionSchemas
{
    /**
     * @return array<string, array<string, mixed>>
     */
    public static function define(): array
    {
        $batch = [
            'dry_run'    => [
                'type'        => 'boolean',
                'description' => 'Preview every target page without saving. Impact lists each page by name.',
            ],
            'batch_size' => ['type' => 'integer'],
            'offset'     => ['type' => 'integer'],
        ];

        $targets = [
            'targets' => [
                'type'  => 'array',
                'items' => ['type' => 'object'],
            ],
        ];

        $selector = [
            'selector' => ['type' => 'object'],
        ];

        return [
            'cloneStructure' => [
                '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.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['clone structure', 'copy section', 'clonar seccion'],
                    'stem'  => ['clone', 'replicate', 'bulk'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($batch, $targets, [
                        'source'       => ['type' => 'object'],
                        'element_id'   => ['type' => 'string'],
                        'area'         => ['type' => 'string'],
                        'position'     => ['type' => 'string'],
                        'parent_id'    => ['type' => 'string'],
                        'reference_id' => ['type' => 'string'],
                    ]),
                    'required'   => ['source', 'targets'],
                ],
            ],
            'bulkUpdateContent' => [
                '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.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['bulk update content', 'update many pages', 'cambiar textos'],
                    'stem'  => ['bulk', 'content', 'lote'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($batch, $targets, $selector, [
                        'content' => ['type' => 'object'],
                    ]),
                    'required'   => ['targets', 'selector'],
                ],
            ],
            'bulkApplyClasses' => [
                '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.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['bulk apply classes', 'add class to pages', 'clases en lote'],
                    'stem'  => ['bulk', 'class', 'lote'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($batch, $targets, $selector, [
                        'add'     => ['type' => 'array', 'items' => ['type' => 'string']],
                        'remove'  => ['type' => 'array', 'items' => ['type' => 'string']],
                        'classes' => ['type' => 'array', 'items' => ['type' => 'string']],
                    ]),
                    'required'   => ['targets', 'selector'],
                ],
            ],
        ];
    }
}
