<?php
/**
 * Official adapter roadmap definition.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Adapter;

/**
 * One prioritized extension adapter target.
 */
final class OfficialAdapterDefinition {
	private string $slug;
	private string $name;
	private int $priority;
	private string $provider_id;
	/**
	 * @var array<int, array<string, string>>
	 */
	private array $signals;
	private ?string $covered_by_provider_id;
	private string $notes;
	/**
	 * Creates an adapter definition.
	 *
	 * @param string                          $slug Stable adapter slug.
	 * @param string                          $name Human-readable extension family name.
	 * @param int                             $priority Priority order.
	 * @param string                          $provider_id Expected provider ID.
	 * @param array<int,array<string,string>> $signals Installed-extension detection signals.
	 * @param string|null                     $covered_by_provider_id Generic provider that can cover this target.
	 * @param string                          $notes Implementation notes.
	 */
	public function __construct(
		string $slug,
		string $name,
		int $priority,
		string $provider_id,
		array $signals,
		?string $covered_by_provider_id,
		string $notes
	) {
		$this->slug                   = $slug;
		$this->name                   = $name;
		$this->priority               = $priority;
		$this->provider_id            = $provider_id;
		$this->signals                = $signals;
		$this->covered_by_provider_id = $covered_by_provider_id;
		$this->notes                  = $notes;
		if ( ! preg_match( '/^[a-z][a-z0-9-]*$/', $this->slug ) ) {
			throw new \InvalidArgumentException( 'Adapter slugs must be lowercase slugs.' );
		}

		if ( ! preg_match( '/^[a-z][a-z0-9-]*$/', $this->provider_id ) ) {
			throw new \InvalidArgumentException( 'Adapter provider IDs must be lowercase slugs.' );
		}
	}

	/**
	 * Stable adapter slug.
	 */
	public function slug(): string {
		return $this->slug;
	}

	/**
	 * Human-readable extension family name.
	 */
	public function name(): string {
		return $this->name;
	}

	/**
	 * Priority order.
	 */
	public function priority(): int {
		return $this->priority;
	}

	/**
	 * Expected provider ID when a dedicated adapter is loaded.
	 */
	public function providerId(): string {
		return $this->provider_id;
	}

	/**
	 * Installed-extension detection signals.
	 *
	 * @return array<int,array<string,string>>
	 */
	public function signals(): array {
		return $this->signals;
	}

	/**
	 * Generic provider that can cover this target.
	 */
	public function coveredByProviderId(): ?string {
		return $this->covered_by_provider_id;
	}

	/**
	 * Implementation notes.
	 */
	public function notes(): string {
		return $this->notes;
	}
}
