<?php
/**
 * Plugin Constants
 *
 * Central definition of every string identifier used by the plugin.
 * All capability checks, option reads/writes, hook registrations, and
 * asset enqueues reference constants from this class so that renaming
 * any identifier is a single-file change.
 *
 * @package Agency_Pulse_Admin_Menu
 * @since   1.0.0
 */

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

class Agency_Pulse_Admin_Menu_Constants {

	// -------------------------------------------------------------------------
	// Prefixes
	// -------------------------------------------------------------------------

	/** All wp_options keys use this prefix. */
	const OPTION_PREFIX = 'aamo_';

	/** User meta keys use this prefix. */
	const USER_META_PREFIX = '_aamo_';

	// -------------------------------------------------------------------------
	// Admin page slugs
	// -------------------------------------------------------------------------

	const PAGE_MENU_BUILDER     = 'aamo_menu_builder';
	const PAGE_SETTINGS         = 'aamo_settings';
	const PAGE_ROLE_ASSIGNMENTS = 'aamo_role_assignments';
	const PAGE_CUSTOMIZE        = 'aamo_customize';

	// -------------------------------------------------------------------------
	// WordPress option keys — current schema
	// -------------------------------------------------------------------------

	/** Named configurations store: associative array keyed by config ID. */
	const OPTION_CONFIGS = 'aamo_menu_configs';

	/** Role-to-config assignment map: role_slug => config_id. */
	const OPTION_ROLE_ASSIGNMENTS = 'aamo_role_assignments';

	/** General plugin settings. */
	const OPTION_SETTINGS = 'aamo_settings';

	/** apwp-ao domain slot auth state — slot-specific JWT, key, and status. */
	const OPTION_AO_CONNECTOR_STATE = 'aamo_ao_connector_state';

	/** Schema version tracker — bump when the stored data structure changes. */
	const OPTION_DB_VERSION = 'aamo_db_version';

	// -------------------------------------------------------------------------
	// WordPress option keys — legacy (migration use only)
	// -------------------------------------------------------------------------

	/**
	 * The old single-config option key from the skeleton build.
	 * Used only in Settings Manager migration logic to detect and convert
	 * installations that pre-date the named-config data model.
	 * Must not be used for any new reads or writes.
	 */
	const OPTION_LEGACY_CONFIG = 'aamo_menu_config';

	// -------------------------------------------------------------------------
	// Capability
	// -------------------------------------------------------------------------

	/**
	 * Custom capability that gates access to all plugin pages and AJAX endpoints.
	 * Granted to the administrator role on activation. Can be granted to any
	 * other role or user via standard WordPress role management.
	 */
	const CAP_MANAGE_MENUS = 'ap_menu_manager';

	// -------------------------------------------------------------------------
	// AJAX action names  (register with 'wp_ajax_' . CONSTANT)
	// -------------------------------------------------------------------------

	const AJAX_SAVE_CONFIG      = 'aamo_save_menu_config';
	const AJAX_RESET_CONFIG     = 'aamo_reset_menu_config';
	const AJAX_GET_MENU         = 'aamo_get_current_menu';
	const AJAX_CREATE_CONFIG    = 'aamo_create_config';
	const AJAX_RENAME_CONFIG    = 'aamo_rename_config';
	const AJAX_DUPLICATE_CONFIG = 'aamo_duplicate_config';
	const AJAX_DELETE_CONFIG    = 'aamo_delete_config';
	const AJAX_SAVE_ASSIGNMENTS = 'aamo_save_role_assignments';
	const AJAX_BACKUP_PUSH      = 'aamo_backup_push';
	const AJAX_BACKUP_PULL      = 'aamo_backup_pull';
	const AJAX_AO_CONNECT       = 'aamo_ao_connect';

	// -------------------------------------------------------------------------
	// Admin-post action names  (register with 'admin_post_' . CONSTANT)
	// -------------------------------------------------------------------------

	const EXPORT_ACTION = 'aamo_export_config';
	const IMPORT_ACTION = 'aamo_import_config';

	// -------------------------------------------------------------------------
	// Cloud backup
	// -------------------------------------------------------------------------

	/** Key used to identify this plugin's backup on the external server. */
	const BACKUP_KEY = 'aamo_config_backup';

	// -------------------------------------------------------------------------
	// Connection health
	// -------------------------------------------------------------------------

	/** Minutes of consecutive API failures before the plugin auto-disconnects. */
	const API_ERROR_DISCONNECT_MINUTES = 4320; // 3 days

	// -------------------------------------------------------------------------
	// Action hooks
	// -------------------------------------------------------------------------

	/** Fires after the plugin registers its own admin pages. */
	const HOOK_REGISTER_MENUS = 'aamo_register_builder_menus';

	/** Fires before the saved config is applied to the admin menu. */
	const HOOK_BEFORE_APPLY_CONFIG = 'aamo_before_apply_menu_config';

	/** Fires after the saved config has been applied to the admin menu. */
	const HOOK_AFTER_APPLY_CONFIG = 'aamo_after_apply_menu_config';

	/** Fires immediately after a config's items are saved. */
	const HOOK_MENU_CONFIG_SAVED = 'aamo_menu_config_saved';

	// -------------------------------------------------------------------------
	// Filter hooks
	// -------------------------------------------------------------------------

	/** Filter the resolved config items before they are applied. */
	const FILTER_MENU_CONFIG = 'aamo_filter_menu_config';

	/** Filter the list of slugs that can never be hidden (safety list). */
	const FILTER_HIDDEN_ITEMS = 'aamo_hidden_menu_items';

	/** Filter the capability required to access the builder. */
	const FILTER_BUILDER_CAPS = 'aamo_builder_capability';

	/** Filter for overriding the pro connector active status check. */
	const FILTER_PRO_ACTIVE = 'aamo_pro_connector_active';

	// -------------------------------------------------------------------------
	// Plugin Access Control
	// -------------------------------------------------------------------------

	/** Option key storing the current access mode. Stored separately from aamo_settings for cheap reads in the user_has_cap filter. */
	const OPTION_ACCESS_MODE = 'aamo_access_mode';

	/** Access mode: anyone with the ap_menu_manager capability (default behaviour). */
	const ACCESS_MODE_DEFAULT  = 'default';

	/** Access mode: only users in the administrator role; non-admin explicit grants are suppressed via filter. */
	const ACCESS_MODE_ADMIN    = 'admin_only';

	/** Access mode: only users with an explicit individual cap grant; ap_menu_manager is removed from the administrator role. */
	const ACCESS_MODE_CAP_ONLY = 'cap_only';

	const AJAX_SET_ACCESS_MODE    = 'aamo_set_access_mode';
	const AJAX_GRANT_MANAGER_CAP  = 'aamo_grant_manager_cap';
	const AJAX_REVOKE_MANAGER_CAP = 'aamo_revoke_manager_cap';

	// -------------------------------------------------------------------------
	// Role Manager
	// -------------------------------------------------------------------------

	/** Nonce action shared by all Role Manager AJAX endpoints. */
	const AJAX_RM_NONCE = 'aamo_role_manager';

	/** AJAX action: grant ap_menu_manager to a role. */
	const AJAX_RM_GRANT_ROLE = 'aamo_rm_grant_role';

	/** AJAX action: revoke ap_menu_manager from a role. */
	const AJAX_RM_REVOKE_ROLE = 'aamo_rm_revoke_role';

	/** AJAX action: grant ap_menu_manager to a specific user. */
	const AJAX_RM_GRANT_USER = 'aamo_rm_grant_user';

	/** AJAX action: revoke ap_menu_manager from a specific user. */
	const AJAX_RM_REVOKE_USER = 'aamo_rm_revoke_user';

	/** AJAX action: search users for the Plugin Access grant-to-user field. */
	const AJAX_RM_SEARCH_USERS = 'aamo_rm_search_users';

	/** AJAX action: fetch a role's capabilities for the capability editor. */
	const AJAX_RM_GET_CAPS = 'aamo_rm_get_caps';

	/** AJAX action: persist capability changes for a role. */
	const AJAX_RM_SAVE_CAPS = 'aamo_rm_save_caps';

	/** AJAX action: clone an existing role into a new custom role. */
	const AJAX_RM_CLONE_ROLE = 'aamo_rm_clone_role';

	/** AJAX action: delete a custom role. */
	const AJAX_RM_DELETE_ROLE = 'aamo_rm_delete_role';

	// -------------------------------------------------------------------------
	// Dashboard Message Widget
	// -------------------------------------------------------------------------

	/** Option key for the dashboard message widget settings (enabled, title, content). */
	const OPTION_DASHBOARD_MESSAGE = 'aamo_dashboard_message';

	/** AJAX action to save the dashboard message settings. */
	const AJAX_SAVE_DASHBOARD_MSG  = 'aamo_save_dashboard_message';

	/** REST API namespace for all apwp-ao external endpoints. */
	const REST_NAMESPACE = 'apwp-ao/v1';

	/** REST API route path for the dashboard message webhook. */
	const REST_DASHBOARD_MSG = '/dashboard-message';

	/** REST API route path for the remote apply-template webhook. */
	const REST_APPLY_TEMPLATE = '/apply-template';

	// -------------------------------------------------------------------------
	// Template Library
	// -------------------------------------------------------------------------

	/** Stores a map of sanitize_key(name) => server slug for previously saved templates. */
	const OPTION_TEMPLATE_SLUGS = 'aamo_template_slugs';

	/** AJAX action: save current config as a named template on the server. */
	const AJAX_TEMPLATE_SAVE   = 'aamo_template_save';

	/** AJAX action: fetch the list of templates from the server. */
	const AJAX_TEMPLATE_LIST   = 'aamo_template_list';

	/** AJAX action: fetch a template payload from the server and apply it. */
	const AJAX_TEMPLATE_APPLY  = 'aamo_template_apply';

	/** AJAX action: delete a template from the server. */
	const AJAX_TEMPLATE_DELETE = 'aamo_template_delete';

	// -------------------------------------------------------------------------
	// Admin Bar Customizer
	// -------------------------------------------------------------------------

	/** Stores the branding icon and site name settings. */
	const OPTION_BRANDING_ICON    = 'aamo_branding_icon';

	/** AJAX action: save admin bar customizer settings. */
	const AJAX_SAVE_BRANDING_ICON = 'aamo_save_branding_icon';

	// -------------------------------------------------------------------------
	// Admin Footer Customizer
	// -------------------------------------------------------------------------

	/** Stores the admin footer customizer settings. */
	const OPTION_ADMIN_FOOTER    = 'aamo_admin_footer';

	/** AJAX action: save admin footer settings. */
	const AJAX_SAVE_ADMIN_FOOTER = 'aamo_save_admin_footer';

	// -------------------------------------------------------------------------
	// Color Customizer
	// -------------------------------------------------------------------------

	/** Stores the 8-slot admin color palette. */
	const OPTION_COLOR_SCHEME    = 'aamo_color_scheme';

	/** AJAX action: save custom color palette. */
	const AJAX_SAVE_COLOR_SCHEME  = 'aamo_save_color_scheme';

	/** AJAX action: reset color palette to WP defaults. */
	const AJAX_RESET_COLOR_SCHEME = 'aamo_reset_color_scheme';

	// -------------------------------------------------------------------------
	// Reset Customization
	// -------------------------------------------------------------------------

	/** AJAX action: reset all customization settings to defaults. */
	const AJAX_RESET_CUSTOMIZATION = 'aamo_reset_customization';

	/** REST route path for the reset-customization webhook. */
	const REST_RESET_CUSTOMIZATION = '/reset-customization';

	// -------------------------------------------------------------------------
	// Admin Layout
	// -------------------------------------------------------------------------

	/** Page slug for the Admin Layout submenu page. */
	const PAGE_LAYOUT = 'aamo_layout';

	/** Option key storing all Admin Layout settings. */
	const OPTION_LAYOUT = 'aamo_layout_settings';

	/** AJAX action: save admin layout settings. */
	const AJAX_SAVE_LAYOUT = 'aamo_save_layout';

	/** AJAX action: reset admin layout settings to defaults. */
	const AJAX_RESET_LAYOUT = 'aamo_reset_layout';

	// -------------------------------------------------------------------------
	// Asset handles
	// -------------------------------------------------------------------------

	const ASSET_HANDLE_CSS         = 'aamo-admin';
	const ASSET_HANDLE_JS          = 'aamo-admin';
	const ASSET_HANDLE_ROLE_JS     = 'aamo-role-assignments';
	const ASSET_HANDLE_SETTINGS_JS = 'aamo-settings';
	const ASSET_HANDLE_LAYOUT_JS   = 'aamo-layout';
	const ASSET_HANDLE_COLLAPSE_JS = 'aamo-collapse';

	// -------------------------------------------------------------------------
	// Schema version
	// -------------------------------------------------------------------------

	const DB_VERSION = '1.0.0';
}
