<?php
/**
 * SuiteCore test double.
 *
 * @package GravityOps\Core
 */

namespace GOSP\GravityOps\Core\SuiteCore;

/**
 * Provides the SuiteCore collaborators used while rendering feedback notices.
 */
final class SuiteCore { // phpcs:ignore Generic.Classes.DuplicateClassName.Found, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- Isolated test replacement.
	/**
	 * Shared test instance.
	 *
	 * @var ?self
	 */
	private static ?self $instance = null;

	/**
	 * Survey products exposed to tests.
	 *
	 * @var array<string,array<string,mixed>>
	 */
	public array $products = [
		'test_' => [
			'title'         => 'Test Plugin',
			'version'       => '1.0.0',
			'plan_resolver' => 'premium',
		],
	];

	/**
	 * Returns the shared test instance.
	 *
	 * @return self
	 */
	public static function instance(): self {
		self::$instance ??= new self();

		return self::$instance;
	}

	/**
	 * Returns a minimal admin shell.
	 *
	 * @return object
	 */
	public function shell(): object {
		return new class() {
			/**
			 * Accepts hidden-page registrations in tests.
			 *
			 * @param string $slug Page slug.
			 * @param array  $args Page arguments.
			 *
			 * @return void
			 */
			public function register_plugin_page( string $slug, array $args ): void {
				unset( $slug, $args );
			}

			/**
			 * Reports that no test page belongs to the shell.
			 *
			 * @param string $page Admin page slug.
			 *
			 * @return bool
			 */
			public function has_page( string $page ): bool {
				unset( $page );

				return false;
			}
		};
	}

	/**
	 * Returns registered test survey products.
	 *
	 * @return array<string,array<string,mixed>>
	 */
	public function survey_products(): array {
		return $this->products;
	}

	/**
	 * Returns a minimal survey helper used by review rendering.
	 *
	 * @return object
	 */
	public function survey_prompter(): object {
		return new class() {
			/**
			 * No-op feedback script renderer.
			 *
			 * @return void
			 */
			public function render_feedback_script(): void {
			}
		};
	}

	/**
	 * Returns feedback endpoint configuration.
	 *
	 * @return object
	 */
	public function config(): object {
		return new class() {
			/**
			 * Returns the review endpoint.
			 *
			 * @return string
			 */
			public function get_review_endpoint(): string {
				return 'https://example.test/review';
			}

			/**
			 * Returns the survey endpoint.
			 *
			 * @return string
			 */
			public function get_survey_endpoint(): string {
				return 'https://example.test/survey';
			}

			/**
			 * Returns the affiliate endpoint.
			 *
			 * @return string
			 */
			public function get_affiliate_url(): string {
				return 'https://example.test/affiliate';
			}
		};
	}
}
