<?php

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

/**
 * Deterministic rules used by the MVP scanner.
 *
 * Rules are deliberately framed as risk signals. They never determine legal
 * compliance and should be updated as official guidance evolves.
 */
final class ClaimPrism_Rules {
	const COMMISSION_FAQ = 'https://commission.europa.eu/document/download/3c257883-bb2a-4dd9-a6dc-501d587bb34f_en?filename=faq-empowerting-consumers-gtd.pdf';
	const DIRECTIVE      = 'https://eur-lex.europa.eu/eli/dir/2024/825/oj/eng';

	public static function all() {
		$rules = array(
			array(
				'id'          => 'generic_environmental_claim',
				'label'       => __( 'Generic environmental claim', 'claimprism' ),
				'severity'    => 'high',
				'description' => __( 'Generic environmental wording may require recognised excellent environmental performance or a clear, prominent specification on the same medium.', 'claimprism' ),
				'source'      => self::COMMISSION_FAQ,
				'phrases'     => array(
					// English.
					'environmentally friendly', 'eco-friendly', 'eco friendly', 'climate friendly', 'carbon friendly',
					'gentle on the environment', 'nature’s friend', "nature's friend", 'environmentally correct',
					'biodegradable', 'biobased', 'green product', 'green choice', 'ecological',
					// Italian.
					'ecologico', 'ecologica', 'eco-friendly', 'amico dell’ambiente', "amico dell'ambiente", 'rispettoso dell’ambiente',
					'rispettoso dell\'ambiente', 'biodegradabile', 'biobased', 'a basso impatto ambientale', 'sostenibile per l’ambiente', "sostenibile per l'ambiente",
					// German.
					'umweltfreundlich', 'klimafreundlich', 'ökologisch', 'biologisch abbaubar', 'umweltschonend',
					// French.
					'respectueux de l’environnement', "respectueux de l'environnement", 'écologique', 'écoresponsable', 'biodégradable',
					// Spanish.
					'respetuoso con el medio ambiente', 'ecológico', 'ecológica', 'biodegradable', 'amigable con el medio ambiente',
					// Dutch.
					'milieuvriendelijk', 'klimaatvriendelijk', 'ecologisch', 'biologisch afbreekbaar',
				),
			),
			array(
				'id'          => 'carbon_neutrality_claim',
				'label'       => __( 'Carbon or climate neutrality claim', 'claimprism' ),
				'severity'    => 'high',
				'description' => __( 'Carbon-neutrality claims need careful review. Product claims based on greenhouse-gas offsetting receive specific treatment under the amended EU rules.', 'claimprism' ),
				'source'      => self::COMMISSION_FAQ,
				'phrases'     => array(
					'carbon neutral', 'carbon-neutral', 'climate neutral', 'climate-neutral', 'carbon positive', 'carbon-positive',
					'carbon compensated', 'carbon-compensated', 'zero carbon', 'net zero product',
					'carbonio neutro', 'neutro per il clima', 'climaticamente neutro', 'impatto climatico zero',
					'klimaneutral', 'co2-neutral', 'co₂-neutral', 'climat neutre', 'neutre en carbone',
					'carbono neutral', 'climáticamente neutro', 'klimaatneutraal', 'co2-neutraal', 'co₂-neutraal',
				),
			),
			array(
				'id'          => 'offsetting_claim',
				'label'       => __( 'Offsetting-based product claim', 'claimprism' ),
				'severity'    => 'critical',
				'description' => __( 'Claims that a product has a neutral, reduced or positive greenhouse-gas impact because of offsetting are a high-priority review signal.', 'claimprism' ),
				'source'      => self::COMMISSION_FAQ,
				'phrases'     => array(
					'carbon offset', 'carbon offsets', 'carbon offsetting', 'offset emissions', 'offsetting emissions',
					'compensate emissions', 'compensating emissions', 'compensazione delle emissioni', 'compensa le emissioni',
					'co2-kompensation', 'co₂-kompensation', 'kompensiert emissionen', 'compensation carbone',
					'compense les émissions', 'compensación de carbono', 'compensa las emisiones', 'CO2-compensatie', 'co₂-compensatie',
				),
			),
			array(
				'id'          => 'future_environmental_performance',
				'label'       => __( 'Future environmental performance claim', 'claimprism' ),
				'severity'    => 'medium',
				'description' => __( 'Future environmental-performance claims may require clear, objective, public and verifiable commitments backed by a detailed implementation plan and independent verification.', 'claimprism' ),
				'source'      => self::COMMISSION_FAQ,
				'patterns'    => array(
					'/\b(?:net[ -]?zero|carbon[ -]?neutral|climate[ -]?neutral)\s+(?:by|before)\s+20\d{2}\b/iu',
					'/\b(?:net[ -]?zero|carbonio neutro|neutralità climatica)\s+(?:entro|prima del)\s+20\d{2}\b/iu',
					'/\b(?:klimaneutral|netto[ -]?null)\s+(?:bis|vor)\s+20\d{2}\b/iu',
					'/\b(?:neutre en carbone|neutralité climatique)\s+(?:d’ici|avant)\s+20\d{2}\b/iu',
					'/\b(?:carbono neutral|cero neto)\s+(?:para|antes de)\s+20\d{2}\b/iu',
				),
			),
			array(
				'id'          => 'sustainability_label_signal',
				'label'       => __( 'Sustainability label or certification signal', 'claimprism' ),
				'severity'    => 'medium',
				'description' => __( 'Voluntary sustainability labels should be checked to confirm that they are based on a certification scheme or established by a public authority.', 'claimprism' ),
				'source'      => self::COMMISSION_FAQ,
				'phrases'     => array(
					'green certified', 'eco certified', 'sustainability certified', 'sustainable certified', 'certified sustainable',
					'certificato green', 'certificato ecologico', 'certificato sostenibile', 'zertifiziert nachhaltig',
					'certifié durable', 'certifié écologique', 'certificado sostenible', 'certificado ecológico', 'duurzaam gecertificeerd',
				),
			),
		);

		return apply_filters( 'claimprism_rules', $rules );
	}

	public static function recognised_performance_markers() {
		return array(
			'eu ecolabel', 'european ecolabel', 'ecolabel ue', 'eu-umweltzeichen',
			'nordic swan', 'nordic swan ecolabel', 'blue angel', 'blauer engel',
			'austrian ecolabel', 'österreichisches umweltzeichen', 'milieukeur',
		);
	}
}
