<?php
/**
 * GTM Kit plugin file.
 *
 * @package GTM Kit
 */

namespace TLA_Media\GTM_Kit\Options;

/**
 * Option Keys - Centralized definition of all GTM Kit options
 *
 * Replaces magic strings throughout the codebase.
 * Provides IDE autocomplete and refactoring support.
 */
final class OptionKeys {

	// General Options.
	public const GENERAL_GTM_ID                  = 'general.gtm_id';
	public const GENERAL_SCRIPT_IMPLEMENTATION   = 'general.script_implementation';
	public const GENERAL_NOSCRIPT_IMPLEMENTATION = 'general.noscript_implementation';
	public const GENERAL_CONTAINER_ACTIVE        = 'general.container_active';
	public const GENERAL_EXCLUDED_URL_PATTERNS   = 'general.excluded_url_patterns';
	public const GENERAL_SGTM_DOMAIN             = 'general.sgtm_domain';
	public const GENERAL_CONSOLE_LOG             = 'general.console_log';
	public const GENERAL_DEBUG_LOG               = 'general.debug_log';
	public const GENERAL_GTM_AUTH                = 'general.gtm_auth';
	public const GENERAL_GTM_PREVIEW             = 'general.gtm_preview';
	public const GENERAL_DATALAYER_PAGE_TYPE     = 'general.datalayer_page_type';
	public const GENERAL_EXCLUDE_USER_ROLES      = 'general.exclude_user_roles';

	// Google Consent Mode v2 options.
	public const GENERAL_GCM_DEFAULT_SETTINGS        = 'general.gcm_default_settings';
	public const GENERAL_GCM_AD_PERSONALIZATION      = 'general.gcm_ad_personalization';
	public const GENERAL_GCM_AD_STORAGE              = 'general.gcm_ad_storage';
	public const GENERAL_GCM_AD_USER_DATA            = 'general.gcm_ad_user_data';
	public const GENERAL_GCM_ANALYTICS_STORAGE       = 'general.gcm_analytics_storage';
	public const GENERAL_GCM_PERSONALIZATION_STORAGE = 'general.gcm_personalization_storage';
	public const GENERAL_GCM_FUNCTIONALITY_STORAGE   = 'general.gcm_functionality_storage';
	public const GENERAL_GCM_SECURITY_STORAGE        = 'general.gcm_security_storage';
	public const GENERAL_GCM_ADS_DATA_REDACTION      = 'general.gcm_ads_data_redaction';
	public const GENERAL_GCM_URL_PASSTHROUGH         = 'general.gcm_url_passthrough';
	public const GENERAL_GCM_WAIT_FOR_UPDATE         = 'general.gcm_wait_for_update';
	public const GENERAL_GCM_REGION                  = 'general.gcm_region';

	// Script gating.
	public const GENERAL_CONSENT_GATING_MODE = 'general.consent_gating_mode';

	// Engagement events.
	public const GENERAL_ENGAGEMENT_EVENT_LOGIN_ENABLED         = 'general.engagement_event_login_enabled';
	public const GENERAL_ENGAGEMENT_EVENT_SIGNUP_ENABLED        = 'general.engagement_event_signup_enabled';
	public const GENERAL_ENGAGEMENT_EVENT_SEARCH_ENABLED        = 'general.engagement_event_search_enabled';
	public const GENERAL_ENGAGEMENT_EVENT_GENERATE_LEAD_ENABLED = 'general.engagement_event_generate_lead_enabled';

	// CMP script attribute support.
	public const GENERAL_CMP_SCRIPT_ATTRIBUTES = 'general.cmp_script_attributes';

	// Integration Options.
	public const INTEGRATIONS_WOOCOMMERCE_INTEGRATION               = 'integrations.woocommerce_integration';
	public const INTEGRATIONS_WOOCOMMERCE_SHIPPING_INFO             = 'integrations.woocommerce_shipping_info';
	public const INTEGRATIONS_WOOCOMMERCE_PAYMENT_INFO              = 'integrations.woocommerce_payment_info';
	public const INTEGRATIONS_WOOCOMMERCE_VARIABLE_PRODUCT_TRACKING = 'integrations.woocommerce_variable_product_tracking';
	public const INTEGRATIONS_WOOCOMMERCE_VIEW_ITEM_LIST_LIMIT      = 'integrations.woocommerce_view_item_list_limit';
	public const INTEGRATIONS_WOOCOMMERCE_DEBUG_TRACK_PURCHASE      = 'integrations.woocommerce_debug_track_purchase';
	public const INTEGRATIONS_WOOCOMMERCE_EXCLUDE_TAX               = 'integrations.woocommerce_exclude_tax';
	public const INTEGRATIONS_CF7_LOAD_JS                           = 'integrations.cf7_load_js';
	public const INTEGRATIONS_CF7_INTEGRATION                       = 'integrations.cf7_integration';
	public const INTEGRATIONS_EDD_DEBUG_TRACK_PURCHASE              = 'integrations.edd_debug_track_purchase';
	public const INTEGRATIONS_EDD_INTEGRATION                       = 'integrations.edd_integration';

	// Premium Options.
	public const PREMIUM_ADDON_INSTALLED     = 'premium.addon_installed';
	public const PREMIUM_PREMIUM_INSTALLED   = 'premium.premium_installed';
	public const PREMIUM_WOO_ADDON_INSTALLED = 'premium.woo_addon_installed';

	// Misc Options.
	public const MISC_AUTO_UPDATE = 'misc.auto_update';

	/**
	 * Parse option key into group and key parts
	 *
	 * @param string $option_key Full option key (e.g., 'general.gtm_id').
	 * @return array{group: string, key: string}
	 */
	public static function parse( string $option_key ): array {
		$parts = explode( '.', $option_key, 2 );
		return [
			'group' => $parts[0],
			'key'   => $parts[1] ?? '',
		];
	}

	/**
	 * Get all option keys
	 *
	 * @return array<string>
	 */
	public static function get_all(): array {
		$reflection = new \ReflectionClass( self::class );
		return array_values( $reflection->getConstants() );
	}

	/**
	 * Check if an option key exists
	 *
	 * @param string $option_key Full option key to check.
	 * @return bool
	 */
	public static function exists( string $option_key ): bool {
		return in_array( $option_key, self::get_all(), true );
	}
}
