<?php

namespace wpsolr\core\classes\hosting_api;

use wpsolr\core\classes\engines\postgresql\WPSOLR_PostgreSQL_Constants;
use wpsolr\core\classes\engines\WPSOLR_AbstractEngineClient;

class WPSOLR_Hosting_Api_PostgreSQL_None extends WPSOLR_Hosting_Api_Abstract {

	const HOSTING_API_ID = 'none_postgresql';

	static public function get_is_disabled(): bool {
		return false;
	}

	public function get_is_host_contains_user_password() {
		return false;
	}

	/**
	 * @inheritdoc
	 */
	public function get_is_no_hosting() {
		return true;
	}

	/**
	 * @inheritdoc
	 */
	public function get_label() {
		return sprintf( self::NONE_LABEL, 'PostgreSQL with TimescaleDB extensions' );
	}

	/**
	 * @inheritdoc
	 */
	public function get_search_engine() {
		return WPSOLR_AbstractEngineClient::ENGINE_POSTGRESQL;
	}

	/**
	 * @inheritdoc
	 */
	public function get_ui_fields_child() {

		$result = [
			[
				self::FIELD_NAME_FIELDS_INDEX_LABEL => [
					self::FIELD_NAME_LABEL                 => 'Table name',
					self::FIELD_NAME_PLACEHOLDER           => 'Table name in Postgres, like "my_db_1". Only characters and "_", no white spaces.',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'a database name',
					],
				]
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_HOST => [
					self::FIELD_NAME_LABEL                 => 'Database host',
					self::FIELD_NAME_PLACEHOLDER           => "localhost or ip adress or hostname. No 'http', no '/', no ':'",
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'an index host',
					],
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
				]
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_PATH => [
					self::FIELD_NAME_LABEL                 => 'Maintenance database',
					self::FIELD_NAME_PLACEHOLDER           => '"postgres" if empty. The default database when performing global operations like creating or dropping other databases.',
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_NOT_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'a maintenance database for your index',
					],
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
				]
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_PORT => [
					self::FIELD_NAME_LABEL                 => 'Database port',
					self::FIELD_NAME_PLACEHOLDER           => '5432 is the default port',
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_INTEGER_MINIMUM_2_DIGITS,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'a valid port',
					],
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => false,
				],
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_KEY => [
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_NOT_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::ERROR_LABEL_EMPTY,
					],
					self::FIELD_NAME_LABEL                 => 'Database user',
					self::FIELD_NAME_PLACEHOLDER           => 'Database user with admin rights to create or connect to a database',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => false,
				],
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_SECRET => [
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_NOT_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::ERROR_LABEL_EMPTY,
					],
					self::FIELD_NAME_LABEL                 => 'Database password',
					self::FIELD_NAME_PLACEHOLDER           => '',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => false,
				],
			],

			/*******************************************************************************************************
			 *
			 * Local LLM/embedders
			 *
			 ******************************************************************************************************/

			[
				self::FIELD_NAME_LLM_PROVIDER => [
					self::FIELD_NAME_LABEL                 => 'LLM inference provider',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
					self::FIELD_NAME_DEFAULT_VALUE         => WPSOLR_PostgreSQL_Constants::AI_PROVIDER_LOCAL_OLLAMA,
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'an LLM inference service',
					],
					self::FIELD_NAME_SELECT_VALUES         => [
						

						WPSOLR_PostgreSQL_Constants::AI_PROVIDER_LOCAL_OLLAMA   => [
							'label'                     => 'Ollama (local)',
							'is_default'                => true,
							'show_fields_when_selected' => [
								self::FIELD_NAME_FIELDS_INDEX_LANGUAGE_CODE
							],
						],
						

					],
				],
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_LANGUAGE_CODE => [
					self::FIELD_NAME_LABEL                 => 'LLM inference provider Url',
					self::FIELD_NAME_PLACEHOLDER           => 'Example with Ollama: http://ollama:11434',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_NOT_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'your service url',
					],
					self::FIELD_NAME_IS_RELATED            => true,
				]
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_WEAVIATE_HUGGINGFACE_CONFIG_MODEL => [
					self::FIELD_NAME_LABEL                 => 'Embedding model',
					self::FIELD_NAME_PLACEHOLDER           => 'Example with Ollama: nomic-embed-text',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'your Embedding model',
					],
					self::FIELD_NAME_IS_RELATED            => true,
				]
			],
			[
				self::FIELD_NAME_FIELDS_INDEX_CATALOG_BRANCH => [
					self::FIELD_NAME_LABEL                 => 'Embedding dimensions<br>Depends on the model',
					self::FIELD_NAME_PLACEHOLDER           => 'Example with model nomic-embed-text: 768',
					self::FIELD_NAME_FORMAT_IS_CREATE_ONLY => true,
					self::FIELD_NAME_FORMAT                => [
						self::FIELD_NAME_FORMAT_TYPE        => self::FIELD_NAME_FORMAT_TYPE_MANDATORY,
						self::FIELD_NAME_FORMAT_ERROR_LABEL => self::PLEASE_ENTER . 'your embedding dimensions',
					],
					self::FIELD_NAME_IS_RELATED            => true,
				]
			],

		];

		return $result;
	}
}