<?php

namespace Waypoint\Agent\Cli;

use Waypoint\Agent\Auth\Role_Manager;
use Waypoint\Agent\Base\Thing;

class Waypoint_Admin extends Thing {

	public function attach_hooks(): void {
		\WP_CLI::add_command( 'waypoint-agent waypoint-admin', [ $this, 'run' ] );
	}

	/**
	 * Assign the Waypoint Super Admin role to a user.
	 *
	 * ## OPTIONS
	 *
	 * <user_id>
	 * : The ID of the user to promote.
	 *
	 * ## EXAMPLES
	 *
	 *     wp waypoint-agent waypoint-admin 1
	 */
	public function run( array $args ): void {
		$user_id = (int) ( $args[0] ?? 0 );

		if ( ! $user_id ) {
			\WP_CLI::error( 'Please provide a valid user ID.' );
		}

		if ( ! get_user_by( 'id', $user_id ) ) {
			\WP_CLI::error( "No user found with ID {$user_id}." );
		}

		Role_Manager::assign( $user_id );
		\WP_CLI::success( "User {$user_id} has been granted the Waypoint Super Admin role." );
	}
}
