<?php
/**
 * Resolved module catalog report.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Extension;

/**
 * Immutable module catalog resolution result.
 */
final class ModuleCatalogReport {
	/**
	 * @var ModuleDefinition[]
	 */
	private array $definitions;
	/**
	 * @var string[]
	 */
	private array $errors;

	/**
	 * @param ModuleDefinition[] $definitions Resolved definitions.
	 * @param string[]           $errors Resolution errors.
	 */
	public function __construct( array $definitions, array $errors = array() ) {
		$this->definitions = array_values( $definitions );
		$this->errors      = array_values( array_unique( array_map( 'strval', $errors ) ) );
	}

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

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

	public function healthy(): bool {
		return array() === $this->errors;
	}
}
