<?php

namespace Waypoint\Agent\Cli;

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

class Sync_Trusted_Admins extends Thing {

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

	/**
	 * Grant the Waypoint Super Admin role to any user on a trusted domain
	 * (waypoint.agency, waypointagency.com, statenweb.com) who doesn't
	 * already have it. Existing roles are left untouched.
	 *
	 * ## EXAMPLES
	 *
	 *     wp waypoint-agent sync-trusted-admins
	 */
	public function run(): void {
		$assigned = Role_Manager::assign_trusted_domain_users();
		\WP_CLI::success( "Granted the Waypoint Super Admin role to {$assigned} user(s)." );
	}
}
