<?php
/**
 * Execution engine request.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Execution;

use ScheduledChanges\Domain\Operation\OperationGraph;
use ScheduledChanges\Domain\Shared\UtcTimestamp;
use ScheduledChanges\Domain\Shared\Uuid;

/**
 * Carries the immutable context required to execute one run.
 */
final class ExecutionRequest {
	private int $run_id;
	private int $version_id;
	private OperationGraph $graph;
	private Uuid $run_uuid;
	private int $actor_id;
	private int $attempt_number;
	private UtcTimestamp $occurrence_at;
	private string $failure_policy;
	/** @var string[] */
	private array $locked_targets;
	private string $lock_token;

	/**
	 * @param string[] $locked_targets Target references held by this run.
	 */
	public function __construct(
		int $run_id,
		int $version_id,
		OperationGraph $graph,
		Uuid $run_uuid,
		int $actor_id,
		int $attempt_number,
		UtcTimestamp $occurrence_at,
		string $failure_policy,
		array $locked_targets,
		string $lock_token
	) {
		$this->run_id         = $run_id;
		$this->version_id     = $version_id;
		$this->graph          = $graph;
		$this->run_uuid       = $run_uuid;
		$this->actor_id       = $actor_id;
		$this->attempt_number = $attempt_number;
		$this->occurrence_at  = $occurrence_at;
		$this->failure_policy = $failure_policy;
		$this->locked_targets = array_values( $locked_targets );
		$this->lock_token     = $lock_token;
	}

	public function runId(): int {
		return $this->run_id;
	}

	public function versionId(): int {
		return $this->version_id;
	}

	public function graph(): OperationGraph {
		return $this->graph;
	}

	public function runUuid(): Uuid {
		return $this->run_uuid;
	}

	public function actorId(): int {
		return $this->actor_id;
	}

	public function attemptNumber(): int {
		return $this->attempt_number;
	}

	public function occurrenceAt(): UtcTimestamp {
		return $this->occurrence_at;
	}

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

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

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