<?php
/**
 * Page-behavior ability schemas.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks\Schemas;

use LolaCoreForBricks\AbilitiesProvider;

/**
 * Door 1 schemas for B13 page settings, conditions, interactions, and dynamic data.
 */
class PageBehaviorSchemas
{
    /**
     * @return array<string, array<string, mixed>>
     */
    public static function define(): array
    {
        $dryRun = [
            'dry_run' => [
                'type'        => 'boolean',
                'description' => 'Preview the write without saving changes.',
            ],
        ];

        $page = [
            'post_id' => ['type' => 'integer'],
            'area'    => ['type' => 'string'],
        ];

        $element = [
            'element_id' => ['type' => 'string'],
        ];

        return [
            'updatePageSettings' => [
                'description' => 'Edit Bricks page settings such as SEO, layout, and page CSS. Template conditions are rejected here. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['page settings', 'page css', 'ajustes de pagina'],
                    'stem'  => ['seo', 'settings', 'page'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, [
                        'post_id'  => ['type' => 'integer'],
                        'settings' => ['type' => 'object'],
                    ]),
                    'required'   => ['post_id', 'settings'],
                ],
            ],
            'setElementConditions' => [
                'description' => 'Set when a Bricks element is shown. Pass an empty list to clear conditions. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['element conditions', 'show if', 'condiciones de elemento'],
                    'stem'  => ['condition', 'visibility', 'condicion'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $page, $element, [
                        'conditions' => ['type' => 'array', 'items' => ['type' => 'object']],
                    ]),
                    'required'   => ['post_id', 'element_id', 'conditions'],
                ],
            ],
            'setElementInteractions' => [
                'description' => 'Set Bricks element interactions such as click, hover, or enter viewport. Custom JavaScript is rejected. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['element interactions', 'on click', 'interacciones'],
                    'stem'  => ['interaction', 'hover', 'click'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $page, $element, [
                        'interactions' => ['type' => 'array', 'items' => ['type' => 'object']],
                    ]),
                    'required'   => ['post_id', 'element_id', 'interactions'],
                ],
            ],
            'listDynamicDataTags' => [
                'description' => 'List Bricks dynamic data tags grouped by provider. Includes ACF tags when ACF is active.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['dynamic data', 'dynamic tags', 'datos dinamicos', 'acf'],
                    'stem'  => ['dynamic', 'acf', 'tag'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => [],
                ],
            ],
            'setDynamicContent' => [
                'description' => 'Assign a discovered Bricks dynamic data tag to an element setting. Unknown tags are rejected. Call with dry_run first.',
                'category'    => AbilitiesProvider::CATEGORY,
                'keywords'    => [
                    'exact' => ['dynamic content', 'insert tag', 'contenido dinamico'],
                    'stem'  => ['dynamic', 'tag', 'acf'],
                ],
                'parameters'  => [
                    'type'       => 'object',
                    'properties' => array_merge($dryRun, $page, $element, [
                        'setting' => ['type' => 'string'],
                        'tag'     => ['type' => 'string'],
                    ]),
                    'required'   => ['post_id', 'element_id', 'tag'],
                ],
            ],
        ];
    }
}
