<?php
/**
 * Detect competing SEO plugins that already emit JSON-LD.
 *
 * @package WPLens
 */

namespace WPLens\Schema;

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

final class ConflictDetector {

	/**
	 * Known SEO plugins that emit JSON-LD by default.
	 * Map: plugin file (relative to /plugins/) → human label.
	 */
	private const CANDIDATES = array(
		'wordpress-seo/wp-seo.php'                => 'Yoast SEO',
		'wordpress-seo-premium/wp-seo-premium.php'=> 'Yoast SEO Premium',
		'seo-by-rank-math/rank-math.php'          => 'Rank Math',
		'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'All in One SEO',
		'wp-seopress/seopress.php'                => 'SEOPress',
		'autodescription/autodescription.php'     => 'The SEO Framework',
		'schema-pro/wp-schema-pro.php'            => 'Schema Pro',
	);

	/**
	 * @return array<int, string> Human-readable list of active conflicting plugins.
	 */
	public static function active_conflicts(): array {
		if ( ! function_exists( 'is_plugin_active' ) ) {
			require_once ABSPATH . 'wp-admin/includes/plugin.php';
		}
		$active = array();
		foreach ( self::CANDIDATES as $path => $label ) {
			if ( is_plugin_active( $path ) ) {
				$active[] = $label;
			}
		}
		return $active;
	}

	public static function has_conflict(): bool {
		return ! empty( self::active_conflicts() );
	}
}
