<?php
/**
 * One-shot installer: avi_prompt_academy_updates_en
 *
 * Goal: create/update wp_option "avi_prompt_academy_updates_en" with an English JSON
 * version of the Academy Updates dictionary (same keys/structure as FR).
 *
 * Usage (safe):
 * - Include this file once from an admin-only context, or hook avi_install_academy_updates_en().
 * - By default, it does nothing if the option already exists. Use ?avi_force_academy_updates_en=1 to overwrite.
 */
defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'avi_install_academy_updates_en' ) ) {
	function avi_install_academy_updates_en() {
		if ( ! function_exists( 'get_option' ) || ! function_exists( 'add_option' ) || ! function_exists( 'update_option' ) ) {
			return;
		}

		$force = false;
		if ( isset( $_GET['avi_force_academy_updates_en'] ) ) {
			$force = (string) $_GET['avi_force_academy_updates_en'] === '1';
		}

		$existing = get_option( 'avi_prompt_academy_updates_en', null );
		if ( ! $force && is_string( $existing ) && trim( $existing ) !== '' ) {
			return;
		}

		$content_en = wp_json_encode(
			array(
				'meta'    => array(
					'version'         => '1.0',
					'description'     => 'AVI Academy Updates — English dictionary extracted from dashboard modals (3 steps + coach tip). Reference for system prompt.',
					'validation_2026' => 'The 12 Vital Signals are strictly Local SEO (Google Maps listing). No mention of Q&A (Google removed FAQ).',
				),
				'entries' => array(
					'radar_croissance'        => array(
						'definition_vip' => "This is your strategic antenna. It doesn’t just measure — it shows you the battles to win (Top 3) to dominate your neighborhood.",
						'etapes'         => array(
							array( 'titre' => 'Keyword selection', 'texte' => 'You choose the queries that matter for your trade and your area.' ),
							array( 'titre' => 'Integration into your listing', 'texte' => 'You place them in your category, description, and services.' ),
							array( 'titre' => 'Success analysis', 'texte' => 'We measure how you climb and alert you if a nearby competitor overtakes you.' ),
						),
						'astuce_coach'   => 'No need to cheat — Google prefers honesty and precision.',
					),
					'radar_placement'         => array(
						'definition_vip' => 'Placement secrets: the zones Google checks first to understand who you are and what you offer.',
						'etapes'         => array(
							array( 'titre' => 'Keyword selection', 'texte' => 'You choose the queries that matter for your trade and your area.' ),
							array( 'titre' => 'Integration into your listing', 'texte' => 'You place them in your category, description, and services.' ),
							array( 'titre' => 'Success analysis', 'texte' => 'We measure how you climb and alert you if a nearby competitor overtakes you.' ),
						),
						'astuce_coach'   => 'Don’t overdo keywords — write for customers first, Google will follow.',
					),
					'radar_search'            => array(
						'definition_vip' => 'Search secrets: the search bar and filters to isolate your performance instantly.',
						'etapes'         => array(
							array( 'titre' => 'The search bar', 'texte' => 'Type a keyword or a neighborhood to isolate performance instantly.' ),
							array( 'titre' => 'Smart filters', 'texte' => 'Neighborhood (your street), City (your territory), Trade (your expertise). Use them to see where you already dominate.' ),
							array( 'titre' => 'Opportunities', 'texte' => 'AVI ranks your keywords by “Potential”. Focus on those that are close to Top 3.' ),
						),
						'astuce_coach'   => 'Good filtering lets you see if you’re the king on your street before conquering the whole city.',
					),
					'radar_strategy_filters'  => array(
						'definition_vip' => 'Strategic filters: target by trade, city, and neighborhood to see what to boost first.',
						'etapes'         => array(
							array( 'titre' => 'Trade targeting', 'texte' => 'Filter your keywords by service (e.g., “men’s haircut” vs “beard”) to see where you are strongest.' ),
							array( 'titre' => 'City dominance', 'texte' => 'Analyze your power across your whole city to capture the main demand flows.' ),
							array( 'titre' => 'Neighborhood anchoring', 'texte' => 'Everything starts here. Become the master of your street and neighborhood before going further.' ),
						),
						'astuce_coach'   => 'Good filtering instantly shows which service needs a boost.',
					),
					'radar_ranking'           => array(
						'definition_vip' => 'Google combines three pillars to rank listings: Distance, Proximity, and Reputation (reviews, completeness, freshness).',
						'etapes'         => array(
							array( 'titre' => 'Analyze your area', 'texte' => 'We look at where you are, what you offer, and what customers say.' ),
							array( 'titre' => 'Compare with nearby competitors', 'texte' => 'We compare you with other listings in your area for the same search.' ),
							array( 'titre' => 'Your power score', 'texte' => 'Google combines everything to position you in results.' ),
						),
						'astuce_coach'   => 'Your visibility is your growth engine: the more stable it is, the more customers you attract without effort.',
					),
					'radar_top3'              => array(
						'definition_vip' => 'The Local Pack — the top 3 results on Google Maps — generates almost all calls and clicks. Being in Top 3 means capturing most local demand.',
						'etapes'         => array(
							array( 'titre' => 'The Google podium', 'texte' => 'Around 70% of Maps clicks go to the top 3 results.' ),
							array( 'titre' => 'Mobile visibility', 'texte' => 'On smartphones, customers often only see the Top 3 without scrolling.' ),
							array( 'titre' => 'Instant trust', 'texte' => 'Ranking at the top proves to customers that you’re the neighborhood leader.' ),
						),
						'astuce_coach'   => 'Top 3 isn’t optional — it’s your #1 growth engine.',
					),
					'radar_plans'             => array(
						'definition_vip' => 'Choose your growth rhythm: Monthly to observe, Weekly to react, Daily Elite to dominate.',
						'etapes'         => array(
							array( 'titre' => 'Monthly', 'texte' => 'To observe your historical position from a distance.' ),
							array( 'titre' => 'Weekly (recommended)', 'texte' => 'To counter nearby competitors and react to Google’s weekly changes.' ),
							array( 'titre' => 'Daily (Elite)', 'texte' => 'To dominate a high-intensity battle zone. You see every move within 24 hours.' ),
						),
						'astuce_coach'   => 'Data consistency is the champions’ secret. Google loves freshness.',
					),
					'ascension_notoriete'     => array(
						'definition_vip' => 'The climb to notoriety: 3 maturity stages to locate the user in the journey (Anchoring, Influence, Authority).',
						'etapes'         => array(
							array( 'titre' => 'Anchoring', 'texte' => 'Solid foundations: category, description, photos. This is what Google checks first.' ),
							array( 'titre' => 'Influence', 'texte' => 'Visibility that attracts: reviews, posts, service area. You become visible in your neighborhood and city.' ),
							array( 'titre' => 'Authority', 'texte' => 'Local domination: Top 3, Guardian Mode active. You are the reference for your trade in your area.' ),
						),
						'astuce_coach'   => 'Each validated level brings you closer to the podium. Finish your current mission before aiming for the next.',
					),
					'mode_gardien'            => array(
						'definition_vip' => 'AVI’s shield that watches your listing day and night to prevent mistakes or hijacks.',
						'etapes'         => array(
							array( 'titre' => '24/7 monitoring', 'texte' => 'Your listing is continuously monitored to detect suspicious changes.' ),
							array( 'titre' => 'Blocking attacks', 'texte' => 'Unauthorized edits or malicious patterns are flagged.' ),
							array( 'titre' => 'Security report', 'texte' => 'You get a clear summary so you can react fast.' ),
						),
						'astuce_coach'   => 'A protected listing means a business that never sleeps.',
					),
					'mode_gardien_boucliers'  => array(
						'definition_vip' => 'How these shields protect you: NAP Shield, Image Cleaner, Spy Alert.',
						'etapes'         => array(
							array( 'titre' => 'NAP lock', 'texte' => 'We prevent anyone from changing your phone number or address.' ),
							array( 'titre' => 'Image cleaning', 'texte' => 'We block ugly or blurry photos posted by third parties.' ),
							array( 'titre' => 'Spy alert', 'texte' => 'We warn you if a nearby competitor changes tactics to overtake you.' ),
						),
						'astuce_coach'   => 'It’s like having a digital security guard in front of your shop 24/7.',
					),
					'mode_gardien_flux'       => array(
						'definition_vip' => 'Which setting to choose: Co‑pilot, Auto‑pilot, or Hybrid.',
						'etapes'         => array(
							array( 'titre' => 'Co‑pilot', 'texte' => 'You’re the boss — you approve every action AVI suggests.' ),
							array( 'titre' => 'Auto‑pilot', 'texte' => 'Total peace of mind — AVI handles everything so you focus on your trade.' ),
							array( 'titre' => 'Hybrid', 'texte' => 'Best of both worlds: manual for reviews, automatic for the rest.' ),
						),
						'astuce_coach'   => 'Start in Co‑pilot to learn, switch to Auto‑pilot to save time.',
					),
					'mode_gardien_valeur'     => array(
						'definition_vip' => 'Understand my net value: listing value, saved (90 days), saved (all time).',
						'etapes'         => array(
							array( 'titre' => 'Net value', 'texte' => 'An estimate of your listing’s value if it were an asset for sale today.' ),
							array( 'titre' => 'Saved (90 days)', 'texte' => 'What you would have spent on Google Ads in the last 3 months to get the same traffic.' ),
							array( 'titre' => 'Saved (all time)', 'texte' => 'Total advertising gains since AVI has been protecting and optimizing your listing.' ),
						),
						'astuce_coach'   => 'Every 5‑star review increases your net value. AVI helps you grow that capital.',
					),
					'mode_gardien_centre'     => array(
						'definition_vip' => 'Decode the signals: Signal intact, Neutralized attempts, AVI history.',
						'etapes'         => array(
							array( 'titre' => 'Signal intact', 'texte' => 'Your 12 vital points (category, name, phone, address…) match what you defined.' ),
							array( 'titre' => 'Neutralized attempts', 'texte' => 'How many times a third party (or an algorithm) tried to change your info without consent.' ),
							array( 'titre' => 'AVI history', 'texte' => 'The logbook of maintenance actions performed by your digital coach.' ),
						),
						'astuce_coach'   => 'If the light is green, relax: your shield is working for you.',
					),
					'mode_gardien_24h'        => array(
						'definition_vip' => 'Your Google Business Profile is your digital storefront sign. Guardian Mode is your 24/7 alarm against mistakes and attacks.',
						'etapes'         => array(
							array( 'titre' => 'Activation', 'texte' => 'Secure connection to Google and subscription setup.' ),
							array( 'titre' => 'Calibration', 'texte' => 'AVI scans your history and competitors to define your seals.' ),
							array( 'titre' => 'Piloting', 'texte' => 'Your shield is active. You move into calm management mode.' ),
						),
						'astuce_coach'   => 'This is the key step to turn a Google listing into a customer engine.',
					),
					'mode_gardien_workflow'   => array(
						'definition_vip' => 'Guardian workflow steps: Activation, Calibration, Piloting.',
						'etapes'         => array(
							array( 'titre' => 'Activation', 'texte' => 'Secure connection to Google and subscription setup.' ),
							array( 'titre' => 'Calibration', 'texte' => 'AVI scans your history and competitors to define your seals.' ),
							array( 'titre' => 'Piloting', 'texte' => 'Your shield is active. You move into calm management mode.' ),
						),
						'astuce_coach'   => 'This is the key step to turn a Google listing into a customer engine.',
					),
					'mode_gardien_status_auth' => array(
						'definition_vip'   => 'Secure connection: the green check means AVI communicates with Google in real time to monitor hijacks and protect your listing.',
						'etapes'           => array(),
						'astuce_coach'     => '',
					),
					'valeur_generee'          => array(
						'definition_vip' => 'This is the money you “earn” each month by attracting customers organically through SEO, without paying for Google ads.',
						'etapes'         => array(
							array( 'titre' => 'CPC analysis', 'texte' => 'We look at how much a click costs in your industry (e.g., €1.25).' ),
							array( 'titre' => 'Visibility volume', 'texte' => 'We count how many times you appear on Maps.' ),
							array( 'titre' => 'Savings calculation', 'texte' => 'We multiply both to estimate the budget you didn’t give to Google Ads.' ),
						),
						'astuce_coach'   => 'That saved money is budget you can reinvest in your business.',
					),
					'les_12_signaux'          => array(
						'definition_vip'   => 'The 12 Maps fields Guardian monitors (2026, without Google FAQ). Signal 1 = Primary Category; signal 2 = Business Name.',
						'validation_2026'  => 'Strictly Local SEO. No mention of Q&A (Google removed FAQ).',
						'signaux'          => array(
							array( 'numero' => 1, 'nom' => 'Primary category (Primary Category)', 'role' => 'Immediate alert if a competitor changes category to overtake you.' ),
							array( 'numero' => 2, 'nom' => 'Business name (Business Name)', 'role' => 'Protection against keyword stuffing or hijacked renames.' ),
							array( 'numero' => 3, 'nom' => 'Phone number', 'role' => 'NAP Shield: blocks phone changes by third parties.' ),
							array( 'numero' => 4, 'nom' => 'Physical address', 'role' => 'Neutralizes attempts to move your map pin.' ),
							array( 'numero' => 5, 'nom' => 'Website link', 'role' => 'Monitors the linked domain to prevent malicious redirects.' ),
							array( 'numero' => 6, 'nom' => 'Opening hours', 'role' => 'Ensures customers never see “closed” due to an error.' ),
							array( 'numero' => 7, 'nom' => 'Service area', 'role' => 'Protects your service area (cities, ZIP codes) from edits.' ),
							array( 'numero' => 8, 'nom' => 'Services', 'role' => 'Protects your service/menu list from deletions.' ),
							array( 'numero' => 9, 'nom' => 'Attributes (Accessibility / Options)', 'role' => 'Locks characteristics (e.g., wheelchair access, reservations).' ),
							array( 'numero' => 10, 'nom' => 'Booking link', 'role' => 'Monitors the appointment/booking link to prevent redirects.' ),
							array( 'numero' => 11, 'nom' => 'Open status (Open / Closed)', 'role' => 'Alerts if the displayed status doesn’t match real hours.' ),
							array( 'numero' => 12, 'nom' => 'Photo & video gallery', 'role' => 'Image Cleaner: flags blurry or degrading customer photos.' ),
						),
						'etapes'           => array(
							array( 'titre' => 'What are these signals?', 'texte' => 'These are the 12 identity points Google uses to index your listing (2026 update, FAQ removed): Primary category, Business name, Phone, Address, Website, Hours, Service area, Services, Attributes, Booking link, Open/closed status, Photo & video gallery.' ),
							array( 'titre' => 'The edit risk', 'texte' => 'On Google, anyone (customers or competitors) can suggest edits to your info. Without protection, your listing can change without you knowing.' ),
							array( 'titre' => 'Neutralization & alerts', 'texte' => 'AVI monitors these points 24/7. If an edit is attempted, Guardian blocks it or alerts you instantly to protect your Maps ranking.' ),
						),
						'astuce_coach'     => 'A listing whose information never changes is a listing Google fully trusts.',
					),
				),
			),
			JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES
		);

		if ( ! is_string( $content_en ) || $content_en === '' ) {
			return;
		}

		if ( is_string( $existing ) && $existing !== null ) {
			update_option( 'avi_prompt_academy_updates_en', $content_en, false );
			return;
		}
		add_option( 'avi_prompt_academy_updates_en', $content_en, '', false );
	}
}

/**
 * Hook (admin only): runs once if option is missing.
 */
if ( function_exists( 'add_action' ) ) {
	add_action(
		'admin_init',
		static function () {
			if ( function_exists( 'current_user_can' ) && ! current_user_can( 'manage_options' ) ) {
				return;
			}
			avi_install_academy_updates_en();
		},
		9
	);
}

