<?php

namespace wpsolr\core\classes\engines;

use wpsolr\core\classes\WpSolrSchema;

/**
 * Some common methods of all engine clients
 *
 */
trait WPSOLR_Client {

	/**
	 * Dos the search engine have an 'exists' filter?
	 * @return bool
	 */
	public function get_has_exists_filter(): bool {
		return true;
	}

	/**
	 * Hierarchy separator
	 * @return string
	 */
	static public function get_facet_hierarchy_separator(): string {
		return WpSolrSchema::FACET_HIERARCHY_SEPARATOR;
	}

	/**
	 * Generate a cacert file for an index.
	 * Stored in WP root to prevent public http access:  /var/www/html/wpsolr_index_my-index-label_cacert.pem
	 *
	 * @param string $index_label
	 *
	 * @return string
	 */
	protected function _get_self_cacert_file( string $index_label ): string {
		// Ensure get_home_path() is declared.
		require_once ABSPATH . 'wp-admin/includes/file.php';

		$file = sprintf( '%swpsolr_index_%s_node_cert.pem', get_home_path(), $index_label );

		return $file;
	}

}
