<?php
/**
 * Provider validation result.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Provider;

/**
 * Machine-readable validation errors and warnings.
 */
final class ValidationResult {
	/**
	 * @var array<int, array{code: string, message: string, path: string}>
	 */
	private array $errors = array();
	/**
	 * @var array<int, array{code: string, message: string, path: string}>
	 */
	private array $warnings = array();
	/**
	 * @param array<int,array{code:string,message:string,path:string}> $errors Validation errors.
	 * @param array<int,array{code:string,message:string,path:string}> $warnings Validation warnings.
	 */
	public function __construct( array $errors = array(), array $warnings = array() ) {
		$this->errors   = $errors;
		$this->warnings = $warnings;
	}

	public static function valid(): self {
		return new self();
	}

	public static function invalid( string $code, string $message, string $path = '' ): self {
		return new self(
			array(
				array(
					'code'    => $code,
					'message' => $message,
					'path'    => $path,
				),
			)
		);
	}

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

	/**
	 * @return array<int,array{code:string,message:string,path:string}>
	 */
	public function errors(): array {
		return $this->errors;
	}

	/**
	 * @return array<int,array{code:string,message:string,path:string}>
	 */
	public function warnings(): array {
		return $this->warnings;
	}
}
