<?php
/**
 * Validates types against the bundled vocabulary subset.
 *
 * Types outside the subset are technical information ("not verified"), not
 * published warnings — the local list is conservative and incomplete vs Schema.org.
 *
 * @package SEOvaultSEO\Schema\Validation\Rules\SchemaOrg
 */

namespace SEOvaultSEO\Schema\Validation\Rules\SchemaOrg;

use SEOvaultSEO\Schema\Validation\Data\SchemaOrgVocabularyCatalog;
use SEOvaultSEO\Schema\Validation\RuleInterface;
use SEOvaultSEO\Schema\Validation\Severity;
use SEOvaultSEO\Schema\Validation\ValidationContext;
use SEOvaultSEO\Schema\Validation\ValidationIssue;

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

/**
 * Reports types outside the plugin's versioned vocabulary as technical information.
 */
class KnownTypeRule implements RuleInterface {

	/**
	 * Get the stable rule code.
	 *
	 * @return string
	 */
	public function get_code() {
		return 'schema.type.unknown';
	}

	/**
	 * Vocabulary type checks apply to typed entities.
	 *
	 * @param ValidationContext $context Validation context.
	 * @return bool
	 */
	public function supports( ValidationContext $context ) {
		return true;
	}

	/**
	 * Report types outside the local vocabulary subset as technical info.
	 *
	 * @param ValidationContext $context Validation context.
	 * @return ValidationIssue[]
	 */
	public function evaluate( ValidationContext $context ) {
		$known  = SchemaOrgVocabularyCatalog::known_types_map();
		$issues = array();

		foreach ( $context->get_entities() as $entity ) {
			foreach ( $entity['types'] ?? array() as $type ) {
				if ( isset( $known[ $type ] ) ) {
					continue;
				}

				$issues[] = new ValidationIssue(
					array(
						'code'        => 'schema.type.unknown',
						'severity'    => Severity::INFO,
						'category'    => 'technical',
						'entity_type' => $type,
						'entity_id'   => $entity['id'] ?? '',
						'path'        => ( $entity['path'] ?? '' ) . '.@type',
						'source'      => $context->get_source(),
						'title_key'   => 'schema.type_unknown.title',
						'message_key' => 'schema.type_unknown.message',
					)
				);
			}
		}

		return $issues;
	}
}
