<?php
/**
 * Canonical field ownership collision.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Field;

/**
 * Records competing write owners and whether scheduling must be blocked.
 */
final class OwnershipCollision {
	private string $fieldId;
	/**
	 * @var string[]
	 */
	private array $providerIds;
	private string $selectedProviderId;
	private bool $blocking;
	/**
	 * @param string[] $providerIds Competing provider IDs in priority order.
	 */
	public function __construct( string $fieldId, array $providerIds, string $selectedProviderId, bool $blocking ) {
		$this->fieldId            = $fieldId;
		$this->providerIds        = $providerIds;
		$this->selectedProviderId = $selectedProviderId;
		$this->blocking           = $blocking;
	}

	public function fieldId(): string {
		return $this->fieldId;
	}

	/**
	 * @return string[]
	 */
	public function providerIds(): array {
		return $this->providerIds;
	}

	public function selectedProviderId(): string {
		return $this->selectedProviderId;
	}

	public function blocking(): bool {
		return $this->blocking;
	}

	/**
	 * @return array{field_id:string,providers:string[],selected_provider:string,blocking:bool}
	 */
	public function toArray(): array {
		return array(
			'field_id'          => $this->fieldId,
			'providers'         => $this->providerIds,
			'selected_provider' => $this->selectedProviderId,
			'blocking'          => $this->blocking,
		);
	}
}
