<?php

namespace ModernFields\CLI\Hooks;

use ModernFields\CLI\Commands\ModernFieldsCommand;
use ModernFields\WordPress\Interfaces\Hooks;

use WP_CLI;

defined('ABSPATH') || exit;

/**
 * Registers the modern-fields WP-CLI command.
 *
 * @since 1.0.0
 */
class CLIRegistration implements Hooks
{
  public function __construct(
    protected ModernFieldsCommand $command,
  ) {}

  /**
   * @since 1.0.0
   */
  public function registerHooks(): void
  {
    if (!defined('WP_CLI') || !WP_CLI) {
      return;
    }

    add_action('cli_init', [$this, 'registerCommands']);
  }

  /**
   * @since 1.0.0
   */
  public function registerCommands(): void
  {
    WP_CLI::add_command('modern-fields', $this->command);
  }
}
