<?php
/**
 * Schema-validation execution context.
 *
 * @package SEOvaultSEO\Schema\Validation
 */

namespace SEOvaultSEO\Schema\Validation;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Carries normalized input and non-content execution metadata to rules.
 */
class ValidationContext {

	/**
	 * Schema input source.
	 *
	 * @var string
	 */
	private $source;

	/**
	 * Normalized schema graph.
	 *
	 * @var array
	 */
	private $graph;

	/**
	 * Normalized entity records.
	 *
	 * @var array
	 */
	private $entities;

	/**
	 * Effective validator limits.
	 *
	 * @var array
	 */
	private $limits;

	/**
	 * Optional canonical URL.
	 *
	 * @var string
	 */
	private $canonical_url;

	/**
	 * Create a validation context.
	 *
	 * @param string $source        Schema source.
	 * @param array  $graph         Normalized schema graph.
	 * @param array  $entities      Normalized entity records.
	 * @param array  $limits        Effective validation limits.
	 * @param string $canonical_url Optional canonical URL.
	 */
	public function __construct( $source, $graph, $entities = array(), $limits = array(), $canonical_url = '' ) {
		$this->source        = in_array( $source, array( 'generated', 'custom', 'live' ), true ) ? $source : 'generated';
		$this->graph         = $graph;
		$this->entities      = $entities;
		$this->limits        = $limits;
		$this->canonical_url = $canonical_url;
	}

	/**
	 * Get the source identifier.
	 *
	 * @return string
	 */
	public function get_source() {
		return $this->source;
	}

	/**
	 * Get the normalized graph.
	 *
	 * @return array
	 */
	public function get_graph() {
		return $this->graph;
	}

	/**
	 * Get normalized entity records.
	 *
	 * @return array
	 */
	public function get_entities() {
		return $this->entities;
	}

	/**
	 * Get an effective limit.
	 *
	 * @param string $name     Limit name.
	 * @param mixed  $fallback Default value.
	 * @return mixed
	 */
	public function get_limit( $name, $fallback = null ) {
		return $this->limits[ $name ] ?? $fallback;
	}

	/**
	 * Get the optional canonical URL.
	 *
	 * @return string
	 */
	public function get_canonical_url() {
		return $this->canonical_url;
	}
}
