<?php
/**
 * Admin dashboard view-formatting facade.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Repository;

// phpcs:disable Squiz.Commenting.FunctionComment.ParamCommentFullStop -- Compact forwarding annotations document the facade surface inline.

/** Routes formatting to view-focused collaborators while preserving the 1.x API. */
final class AdminDashboardDisplayFormatter {
	private AdminLaunchDisplayFormatter $launches;
	private AdminRecordingDisplayFormatter $recordings;
	private AdminQueueDisplayFormatter $queue;
	private AdminDiagnosticsDisplayFormatter $diagnostics;

	/** Creates the view-focused formatting collaborators. */
	public function __construct() {
		$values            = new AdminDashboardValueFormatter();
		$this->launches    = new AdminLaunchDisplayFormatter( $values );
		$this->recordings  = new AdminRecordingDisplayFormatter( $values );
		$this->queue       = new AdminQueueDisplayFormatter( $values );
		$this->diagnostics = new AdminDiagnosticsDisplayFormatter( $values );
	}

	/** @param mixed $value */
	public function displayText( $value ): string {
		return $this->diagnostics->displayText( $value );
	}

	/** @param int $user_id User ID. */
	public function ownerName( int $user_id ): string {
		return $this->diagnostics->ownerName( $user_id );
	}

	/**
	 * @param array<string,mixed> $row Row.
	 * @return array<string,mixed>
	 */
	public function launchRow( array $row ): array {
		return $this->launches->launchRow( $row );
	}

	/**
	 * @param array<string,mixed> $row Row.
	 * @return array<string,mixed>
	 */
	public function runRow( array $row ): array {
		return $this->queue->runRow( $row );
	}

	/**
	 * @param array<string,mixed> $row Row.
	 * @return array<string,mixed>
	 */
	public function targetRow( array $row, string $context, bool $apply_provider_hooks = true ): array {
		return $this->launches->targetRow( $row, $context, $apply_provider_hooks );
	}

	/**
	 * Extracts an integer ID from a canonical reference.
	 *
	 * @param string $reference Canonical reference.
	 * @param int    $fallback Fallback ID.
	 */
	public function referenceId( string $reference, int $fallback = 0 ): int {
		return $this->diagnostics->referenceId( $reference, $fallback );
	}

	/** @param mixed $value */
	public function datePart( $value, string $timezone ): string {
		return $this->launches->datePart( $value, $timezone );
	}

	/** @param mixed $value */
	public function timePart( $value, string $timezone ): string {
		return $this->launches->timePart( $value, $timezone );
	}

	/**
	 * @param array<int,array<string,mixed>> $rows Rows.
	 * @return array<int,array<string,mixed>>
	 */
	public function operationRows( array $rows ): array {
		return $this->launches->operationRows( $rows );
	}

	/** @param mixed $value Saved restore-point value. */
	public function restorePreviewValue( $value, string $field, string $type, bool $sensitive ): string {
		return $this->launches->restorePreviewValue( $value, $field, $type, $sensitive );
	}

	/**
	 * @param array<string,mixed> $row Row.
	 * @return array<string,mixed>
	 */
	public function recordingRow( array $row, callable $target_row, callable $reference_id, callable $owner_name, callable $display_text ): array {
		return $this->recordings->recordingRow( $row, $target_row, $reference_id, $owner_name, $display_text );
	}
}
