<?php
/**
 * Persona Dashboards Module.
 *
 * Adds role-tailored widgets to the WordPress dashboard:
 *   - Platform Manager: site-wide pulse, recent content, optional store snapshot.
 *   - Editor: editorial pipeline, top posts by engagement.
 *   - Community Manager: engagement pulse, moderation queue, recent comments.
 *   - Author: personal content stats and recent posts.
 *
 * Personas are detected by capability and a user may hold several at once
 * (multi-role is first-class — they see every applicable widget set). Widgets
 * are additive: the native dashboard is left intact. Data is cached, with an
 * hourly cron pre-warm so admin loads are cache hits.
 *
 * @package Platform\Helm\Modules\Persona_Dashboards
 */

declare( strict_types = 1 );

namespace Platform\Helm\Modules\Persona_Dashboards;

use Platform\Helm\Contracts\ModuleInterface;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

final class PersonaDashboardsModule implements ModuleInterface {

	public const PERSONA_MANAGER   = 'manager';
	public const PERSONA_EDITOR    = 'editor';
	public const PERSONA_AUTHOR    = 'author';
	public const PERSONA_COMMUNITY = 'community';
	public const PERSONA_DEFAULT   = 'default';

	private PersonaDetector $detector;
	private DashboardOrchestrator $orchestrator;
	private CronWarmer $warmer;

	public function __construct() {
		$this->detector     = new PersonaDetector();
		$this->orchestrator = new DashboardOrchestrator( $this->detector );
		$this->warmer       = new CronWarmer();
	}

	public function id(): string {
		return 'persona_dashboards';
	}

	public function name(): string {
		return __( 'Persona Dashboards', 'platform-helm' );
	}

	public function description(): string {
		return __( 'Adds role-tailored widgets to the WordPress dashboard — platform metrics for managers, editorial pipeline for editors, engagement for community managers, and personal stats for authors. Multi-role users see every set that applies. Native dashboard is left intact.', 'platform-helm' );
	}

	public function default_enabled(): bool {
		return false;
	}

	public function boot(): void {
		$this->orchestrator->register_hooks();
		$this->warmer->register_hooks();
	}
}
