<?php
/**
 * Product-editor Record Changes entry adapter.
 *
 * @package ScheduledChangesWooCommerce
 */

namespace ScheduledChangesWooCommerce\CoreCompat\Admin;

use ScheduledChanges\Domain\Recording\RecordingSession;
use ScheduledChanges\Domain\Shared\Uuid;
use ScheduledChanges\Recording\RecordingService;
use ScheduledChanges\Repository\LaunchRepository;
use ScheduledChanges\Repository\LaunchVersionRepository;
use ScheduledChanges\Repository\RecordingSessionRepository;
use ScheduledChanges\Scheduler\SchedulerService;
use ScheduledChangesWooCommerce\CoreCompat\Recording\RecordingPendingTermStore;

/** Thin WordPress entry adapter delegating recording orchestration. */
final class ProductEditorRecordingController {
	private ProductEditorRecordingCoordinator $coordinator;

	public function __construct(
		RecordingSessionRepository $recordings,
		RecordingService $recording_service,
		?SchedulerService $scheduler,
		?RecordingPendingTermStore $pending_terms = null,
		?LaunchRepository $launches = null,
		?LaunchVersionRepository $versions = null,
		?ProductEditorRecordingRequestGuard $request_guard = null
	) {
		$this->coordinator = new ProductEditorRecordingCoordinator(
			$recordings,
			$recording_service,
			$scheduler,
			$pending_terms,
			$launches,
			$versions,
			$request_guard
		);
	}

	public function register(): void {
		$this->coordinator->register();
	}

	public function registerNativeTaxonomyCreationInterceptors(): void {
		$this->coordinator->registerNativeTaxonomyCreationInterceptors();
	}

	/**
	 * Registers an interceptor for a native product taxonomy.
	 *
	 * @param string|string[]                  $object_type Object types.
	 * @param array<string,mixed>|\WP_Taxonomy $taxonomy_object Taxonomy object.
	 */
	public function registerNativeTaxonomyCreationInterceptor( string $taxonomy, $object_type = array(), $taxonomy_object = array() ): void {
		$this->coordinator->registerNativeTaxonomyCreationInterceptor( $taxonomy, $object_type, $taxonomy_object );
	}

	public function enqueue( string $hook_suffix ): void {
		$this->coordinator->enqueue( $hook_suffix );
	}

	/** @return array<string,mixed>|null */
	public function dataForPost( int $post_id ): ?array {
		return $this->coordinator->dataForPost( $post_id );
	}

	public function startRecording(): void {
		$this->coordinator->startRecording();
	}

	public function ajaxStartRecording(): void {
		$this->coordinator->ajaxStartRecording();
	}

	public function ajaxSaveRecordingShadow(): void {
		$this->coordinator->ajaxSaveRecordingShadow();
	}

	public function ajaxCancelRecording(): void {
		$this->coordinator->ajaxCancelRecording();
	}

	public function ajaxFinalizeRecording(): void {
		$this->coordinator->ajaxFinalizeRecording();
	}

	public function ajaxScheduleRecording(): void {
		$this->coordinator->ajaxScheduleRecording();
	}

	public function ajaxCreatePendingTerm(): void {
		$this->coordinator->ajaxCreatePendingTerm();
	}

	public function maybeInterceptNativeHierarchicalTermCreation(): void {
		$this->coordinator->maybeInterceptNativeHierarchicalTermCreation();
	}

	/**
	 * @param string[]                $names Submitted names.
	 * @param array<int|string,mixed> $submitted_terms Existing terms.
	 * @return array{terms:array<int,array<string,mixed>>,assignment:array<int,int|string>}
	 */
	public function recordPendingHierarchicalTermCreation( RecordingSession $session, string $taxonomy, array $names, array $submitted_terms, string $parent_value ): array {
		return $this->coordinator->recordPendingHierarchicalTermCreation( $session, $taxonomy, $names, $submitted_terms, $parent_value );
	}

	/** @return array<string,mixed> */
	public function saveRecordingShadow( Uuid $uuid ): array {
		return $this->coordinator->saveRecordingShadow( $uuid );
	}

	/** @return array<string,mixed> */
	public function finalizeForModal( Uuid $uuid, bool $acknowledge_unsupported_metadata = false ): array {
		return $this->coordinator->finalizeForModal( $uuid, $acknowledge_unsupported_metadata );
	}

	/** @return array<string,mixed> */
	public function scheduleForModal( Uuid $uuid, int $version_id, string $date, string $time ): array {
		return $this->coordinator->scheduleForModal( $uuid, $version_id, $date, $time );
	}
}
