<?php

namespace Waypoint\Agent\Admin;

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

class Key_Notice extends Thing {

	public function attach_hooks(): void {
		add_action( 'admin_notices', [ $this, 'maybe_show' ] );
	}

	public function maybe_show(): void {
		if ( ! current_user_can( \Waypoint\Agent\Auth\Role_Manager::CAP ) ) {
			return;
		}
		if ( null !== ( new Hmac_Auth() )->get_key() ) {
			return;
		}
		?>
		<div class="notice notice-error">
			<p>
				<strong>Waypoint Agent</strong> &mdash;
				<?php esc_html_e( 'WAYPOINT_AGENT_KEY is not set. HMAC-signed REST requests will be rejected until this is configured.', 'waypoint-agent' ); ?>
			</p>
			<p>
				<?php esc_html_e( 'Run the following WP-CLI command to generate and save the key automatically:', 'waypoint-agent' ); ?>
			</p>
			<p><code>wp waypoint-agent rotate-key</code></p>
		</div>
		<?php
	}
}
