<?php
/**
 * File: app/Admin/config/embedding.php
 *
 * @package KimaAI
 * @since 1.3.1
 */

use KimaAI\Helper;

return [
  'order' => 3,
  'schema' => [
    'type' => 'object',
    'isOpen' => true,
    'title' => __('Embedding', 'kimaai'),
    'icon' => 'Embedding',
    'properties' => [
      'embedEnvs' => [
        'type' => 'array',
        'saveType' => 'repeatable',
        'auto' => 'first_sync:aiServices.aiEnvs',
        'title' => __('Embed Envs', 'kimaai'),
        'link' => 'embed-envs',
        'pageTitle' => __('Embedding Environments', 'kimaai'),
        'pageDescription' => __('Configure environments for embeddings', 'kimaai'),
        'onlyPremium' => !Helper::isPremium(),
        'actions' => [
          'test-connection' => '/kimaai/v1/embeddings/test-connection',
        ],
        'sections' => [
          'score' => [
            'title' => __('Score', 'kimaai'),
            'panel' => true,
            'initialOpen' => false,
          ],
          'aiEnv' => [
            'title' => __('AI Environment', 'kimaai'),
            'description' => __('Choose the AI environment for embeddings. If empty, the default embedding environment is used.', 'kimaai'),
            'panel' => true,
            'initialOpen' => false,
          ],
        ],
        'items' => [
          'type' => 'object',
          'default' => [],
          'properties' => [
            'id' => [
              'type' => 'string',
              'default' => '',
            ],
            'name' => [
              'type' => 'string',
              'default' => 'default',
              'component' => 'TextField',
              'props' => [
                'label' => __('Environment Name', 'kimaai'),
                'description' => __('A name to identify this embedding environment.', 'kimaai'),
              ],
            ],
            'provider' => [
              'type' => 'string',
              'default' => 'pinecone',
              'component' => 'SelectField',
              'props' => [
                'label' => __('Vector Database Provider', 'kimaai'),
                'description' => __('Select the vector database provider to use for storing embeddings.', 'kimaai'),
                'options' => [
                  [
                    'label' => __('Pinecone', 'kimaai'),
                    'value' => 'pinecone',
                  ],
                  [
                    'label' => __('Qdrant', 'kimaai'),
                    'value' => 'qdrant',
                  ],
                ],
              ],
            ],
            'apiKey' => [
              'type' => 'string',
              'default' => '',
              'component' => 'TextField',
              'props' => [
                'type' => 'password',
                'label' => __('API Key', 'kimaai'),
                'description' => __('Put your vector database API key here', 'kimaai'),
              ],
            ],
            'serverHost' => [
              'type' => 'string',
              'default' => '',
              'component' => 'TextField',
              'props' => [
                'type' => 'text',
                'label' => __('Index Host', 'kimaai'),
                'description' => __('Put your vector database Index host here (e.g. example-1234.svc.us-west1.pinecone.io)', 'kimaai'),
              ],
            ],
            'collection' => [
              'type' => 'string',
              'default' => '',
              'component' => 'TextField',
              'condition' => [
                'field' => 'provider',
                'operator' => '=',
                'value' => 'qdrant',
              ],
              'props' => [
                'type' => 'text',
                'label' => __('Collection', 'kimaai'),
                'description' => __('Collections separate site data. If empty, Qdrant creates one with 1536 dimensions.', 'kimaai'),
              ],
            ],
            'namespace' => [
              'type' => 'string',
              'default' => '',
              'component' => 'TextField',
              'condition' => [
                'field' => 'provider',
                'operator' => '=',
                'value' => 'pinecone',
              ],
              'props' => [
                'type' => 'text',
                'label' => __('Namespace', 'kimaai'),
                'description' => __('Use a namespace to separate site data in the same server or index. Optional.', 'kimaai'),
              ],
            ],
            'aiEnv' => [
              'section' => 'aiEnv',
              'type' => 'string',
              'default' => '',
              'component' => 'SelectField',
              'props' => [
                'label' => __('AI Environment', 'kimaai'),
                'description' => __('Select the AI environment to use for generating embeddings in this embedding environment.', 'kimaai'),
                'options' => Helper::getAiEnvsOptions(),
              ],
            ],
            'aiModel' => [
              'section' => 'aiEnv',
              'type' => 'string',
              'default' => 'text-embedding-3-small',
              'component' => 'SelectField',
              'props' => [
                'label' => __('AI Model', 'kimaai'),
                'description' => __('Select the AI model to use for generating embeddings in this embedding environment.', 'kimaai'),
                'options' => Helper::aiProviderModelOptions('aiEnv', ['embedding']),
              ],
            ],
            'minScore' => [
              'section' => 'score',
              'type' => 'integer',
              'default' => 35,
              'component' => 'RangeField',
              'props' => [
                'label' => __('Min Score', 'kimaai'),
                'description' => __('The minimum score the embeddings need to have to be returned. Between 0 and 100 and defaults to 35.', 'kimaai'),
                'initialPosition' => 35,
                'min' => 1,
                'max' => 100,
                'step' => 1,
              ],
            ],
            'maxResults' => [
              'section' => 'score',
              'type' => 'number',
              'default' => 10,
              'component' => 'RangeField',
              'props' => [
                'label' => __('Max Results', 'kimaai'),
                'description' => __('Maximum embeddings to return as context. Use 1 to 100; default is 10.', 'kimaai'),
                'initialPosition' => 10,
                'min' => 1,
                'max' => 100,
                'step' => 1,
              ],
            ],
          ],
        ],
      ],
      'embedSettings' => [
        'type' => 'object',
        'title' => __('Settings', 'kimaai'),
        'link' => 'embed-settings',
        'pageTitle' => __('Embedding Settings', 'kimaai'),
        'pageDescription' => __('General settings for the embedding system.', 'kimaai'),
        'onlyPremium' => !Helper::isPremium(),
        'sections' => [
          'onPublish' => [
            'title' => __('On First Publish', 'kimaai'),
            'description' => __('Embed a post automatically the first time it is published.', 'kimaai'),
          ],
          'onUpdate' => [
            'title' => __('On Update', 'kimaai'),
            'description' => __('Re-embed a post automatically when its content changes. Only applies to posts that already have an existing embedding in the vector database — posts without one are skipped.', 'kimaai'),
          ],
        ],
        'properties' => [
          'autoEmbedOnPublish' => [
            'section' => 'onPublish',
            'type' => 'boolean',
            'default' => true,
            'component' => 'ToggleField',
            'props' => [
              'label' => __('Auto-embed on first publish', 'kimaai'),
              'checked' => true,
              'description' => __('Automatically embed the post in the background the first time it is published, including scheduled posts and programmatic publishes.', 'kimaai'),
            ],
          ],
          'autoReEmbedOnUpdate' => [
            'section' => 'onUpdate',
            'type' => 'boolean',
            'default' => true,
            'component' => 'ToggleField',
            'props' => [
              'label' => __('Auto re-embed on update', 'kimaai'),
              'checked' => true,
              'description' => __('Automatically re-embed the post in the background whenever its content is updated. Posts that have not been embedded yet are not affected.', 'kimaai'),
            ],
          ],
        ],
      ],
      'embedding' => [
        'type' => null,
        'title' => __('Sync', 'kimaai'),
        'link' => 'embedding',
        'sharedTabComponent' => 'EmbeddingHeader',
        'tabs' => [
          [
            'name' => 'sync',
            'title' => __('Sync', 'kimaai'),
            'pageTitle' => __('Sync', 'kimaai'),
            'pageDescription' => __('Sync WordPress content with the configured embedding model and provider.', 'kimaai'),
            'component' => 'SyncPanel',
          ],
          [
            'name' => 'query',
            'title' => __('Query', 'kimaai'),
            'pageTitle' => __('Query', 'kimaai'),
            'pageDescription' => __('Test semantic search against embedded content using the configured vector database.', 'kimaai'),
            'component' => 'QueryPanel',
          ],
          [
            'name' => 'collections',
            'title' => __('Collections', 'kimaai'),
            'pageTitle' => __('Collections / Indexes', 'kimaai'),
            'pageDescription' => __('Manage your embedding collections. Collections are used to group your embedded content.', 'kimaai'),
            'component' => 'CollectionsPanel',
          ],
          [
            'name' => 'health',
            'title' => __('Health', 'kimaai'),
            'pageTitle' => __('Health', 'kimaai'),
            'pageDescription' => __('Check vector database and AI environment connectivity.', 'kimaai'),
            'component' => 'HealthPanel',
          ],
        ],
        'onlyPremium' => !Helper::isPremium(),
        'showSaveButton' => false,
      ],
    ],
  ],
];
