<?php
declare( strict_types=1 );

namespace FiboFilters\Indexer;

use FiboFilters\Filters\FilterSources;
use FiboFilters\Filters\StoreFilters;
use FiboFilters\Index\Descriptors;
use FiboFilters\Index\Documents;
use FiboFilters\Index\Sources;
use FiboFilters\Index\Values;
use FiboFilters\Indexer\Filters\Document;
use FiboFilters\Integrations\Multilingual;
use FiboFilters\Util\Cache;
use FiboFilters\Util\DbUtil;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class DocumentFactory
 */
class DocumentFactory {

	/** @var Cache */
	private $cache;

	/** @var DbUtil */
	private $db_util;

	/** @var FilterSources */
	private $filter_sources;

	/** @var Multilingual */
	protected $multilingual;

	/** @var StoreFilters */
	private $store_filters;

	/** @var Descriptors */
	private Descriptors $descriptors;

	/** @var Documents */
	private Documents $documents;

	/** @var Sources */
	private Sources $sources;

	/** @var Values */
	private Values $values;

	public function __construct(
		Cache $cache,
		DbUtil $db_util,
		Multilingual $multilingual,
		StoreFilters $store_filters,
		FilterSources $filter_sources,
		Descriptors $descriptors,
		Documents $documents,
		Sources $sources,
		Values $values
	) {
		$this->cache          = $cache;
		$this->db_util        = $db_util;
		$this->multilingual   = $multilingual;
		$this->store_filters  = $store_filters;
		$this->filter_sources = $filter_sources;
		$this->descriptors    = $descriptors;
		$this->documents      = $documents;
		$this->sources        = $sources;
		$this->values         = $values;
	}

	public function get( array $data, array $config = [] ): Document {
		return new Document(
			$data,
			$config,
			$this->multilingual,
			$this->db_util,
			$this->cache,
			$this->store_filters,
			$this->filter_sources,
			$this->descriptors,
			$this->documents,
			$this->sources,
			$this->values
		);
	}

	public function get_by_id( int $id, array $config = [] ): Document {
		$data = [ 'ID' => $id ];

		return new Document(
			$data,
			$config,
			$this->multilingual,
			$this->db_util,
			$this->cache,
			$this->store_filters,
			$this->filter_sources,
			$this->descriptors,
			$this->documents,
			$this->sources,
			$this->values
		);
	}
}
