<?php
class Lockee_Hooks
{
  // Priorités des hooks
  const PRIORITY_DEFAULT = 10;
  const PRIORITY_EARLY = 1;
  const PRIORITY_LATE = 99;

  public static function register_all()
  {
    self::register_ajax_hooks();
    self::register_assets_hooks();
    self::register_block_hooks();
    self::register_iframe_hooks();
    self::register_metabox_hooks();
    self::register_post_types_hooks();
    self::register_migration_hooks();
    self::register_settings_hooks();
    self::register_shortcode_hooks();
    self::register_update_hooks();
    self::register_content_hooks();
  }

  private static function register_ajax_hooks()
  {
    add_action("wp_fast_ajax_verifcode", [Lockee_Ajax::get_instance(), 'verify_code'], self::PRIORITY_DEFAULT);
    add_action("wp_fast_ajax_nopriv_verifcode", [Lockee_Ajax::get_instance(), 'verify_code'], self::PRIORITY_DEFAULT);
  }

  private static function register_assets_hooks()
  {
    add_action('wp_enqueue_scripts', [Lockee_Assets::get_instance(), 'enqueue_scripts'], self::PRIORITY_DEFAULT);
    add_action('admin_enqueue_scripts', [Lockee_Assets::get_instance(), 'enqueue_admin_scripts'], self::PRIORITY_DEFAULT);
    add_action('enqueue_block_assets', [Lockee_Assets::get_instance(), 'enqueue_block_editor_styles'], self::PRIORITY_DEFAULT);
    add_action('enqueue_block_editor_assets', [Lockee_Assets::get_instance(), 'enqueue_block_editor_config'], self::PRIORITY_DEFAULT);
  }

  private static function register_block_hooks()
  {
    add_action('init', [Lockee_Block::get_instance(), 'lockee_block_init'], self::PRIORITY_DEFAULT);
  }

  public static function register_iframe_hooks()
  {
    add_filter('query_vars', [Lockee_Iframe::get_instance(), 'add_query_vars'], self::PRIORITY_DEFAULT);
    add_action('template_redirect', [Lockee_Iframe::get_instance(), 'handle_iframe_template'], self::PRIORITY_DEFAULT);
  }

  private static function register_metabox_hooks()
  {
    add_action('add_meta_boxes', [Lockee_Metabox::get_instance(), 'initialize_metabox'], self::PRIORITY_DEFAULT);
    add_action('save_post', [Lockee_Metabox::get_instance(), 'save_metabox'], self::PRIORITY_DEFAULT);
    add_action('admin_post_lockee_reset_stats', [Lockee_Metabox::get_instance(), 'handle_reset_stats'], self::PRIORITY_DEFAULT);
    add_action('wp_ajax_lockee_reset_stats_ajax', [Lockee_Metabox::get_instance(), 'handle_reset_stats_ajax'], self::PRIORITY_DEFAULT);
  }

  private static function register_migration_hooks()
  {
    add_action('admin_notices', [Lockee_Migration::get_instance(), 'migration_notice'], self::PRIORITY_DEFAULT);
    add_action('admin_init', [Lockee_Migration::get_instance(), 'maybe_run_migration'], self::PRIORITY_DEFAULT);
    add_action('admin_menu', [Lockee_Migration::get_instance(), 'add_migration_page'], self::PRIORITY_DEFAULT);
    add_action('wp_ajax_lockee_migration_progress', [Lockee_Migration::get_instance(), 'ajax_migration_progress'], self::PRIORITY_DEFAULT);
    add_action('admin_enqueue_scripts', [Lockee_Migration::get_instance(), 'enqueue_migration_scripts'], self::PRIORITY_DEFAULT);
  }

  private static function register_post_types_hooks()
  {
    add_action('init', [Lockee_Post_Types::get_instance(), 'register_post_types'], self::PRIORITY_DEFAULT);
    add_filter('post_type_link', [Lockee_Post_Types::get_instance(), 'custom_post_type_link'], self::PRIORITY_EARLY, 3);
    add_action('wp_head', [Lockee_Post_Types::get_instance(), 'add_noindex_meta'], self::PRIORITY_DEFAULT);
    add_action('admin_head', [Lockee_Post_Types::get_instance(), 'add_columns_styles'], self::PRIORITY_DEFAULT);
    add_filter('rest_authentication_errors', [Lockee_Post_Types::get_instance(), 'restrict_rest_access'], self::PRIORITY_DEFAULT);
  }

  private static function register_settings_hooks()
  {
    add_action('admin_menu', [Lockee_Settings::get_instance(), 'add_settings_page'], self::PRIORITY_DEFAULT);
    add_action('admin_init', [Lockee_Settings::get_instance(), 'register_settings'], self::PRIORITY_DEFAULT);
  }

  private static function register_shortcode_hooks()
  {
    add_shortcode('lockee', [Lockee_Shortcode::get_instance(), 'shortcode']);
  }

  private static function register_update_hooks()
  {
    add_action('upgrader_process_complete', [Lockee_Update::get_instance(), 'handle_update'], self::PRIORITY_DEFAULT, 2);
  }

  private static function register_content_hooks()
  {
    add_filter('the_content', [Lockee_Content::get_instance(), 'display_content'], self::PRIORITY_LATE);
  }
}
