<?php
/**
 * Canonical change collection.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Provider;

use ArrayIterator;
use Countable;
use IteratorAggregate;
use Traversable;

/**
 * @implements IteratorAggregate<int,Change>
 */
final class ChangeCollection implements Countable, IteratorAggregate {
	/**
	 * @var Change[]
	 */
	private array $changes = array();
	/**
	 * @param Change[] $changes Canonical changes.
	 */
	public function __construct( array $changes = array() ) {
		$this->changes = $changes;
	}

	public function count(): int {
		return count( $this->changes );
	}

	/**
	 * @return Traversable<int,Change>
	 */
	public function getIterator(): Traversable {
		return new ArrayIterator( $this->changes );
	}

	/**
	 * @return Change[]
	 */
	public function all(): array {
		return $this->changes;
	}
}
