<?php

namespace FleekDash\Routes\Groups;

use FleekDash\Libs\API\Route;
use FleekDash\Libs\API\RouteAuthMiddleware;
use FleekDash\Controllers\Universal\CategoriesController;
use FleekDash\Controllers\Universal\MetricsController;
use FleekDash\Controllers\Universal\SourcesController;
use FleekDash\Controllers\Universal\DataController;
use FleekDash\Controllers\Universal\DashboardsController;
use FleekDash\Controllers\Universal\SystemController;

/**
 * Universal Analytics Routes
 *
 * API routes for Universal Analytics System:
 * - Categories management
 * - Metrics management
 * - Data sources management
 * - Metric data queries
 * - Dashboard templates
 * - User dashboards
 * - System statistics
 *
 * @package FleekDash\Routes\Groups
 * @since 2.2.0
 */
class UniversalAnalyticsRoutes
{
    /**
     * Register all universal analytics routes
     *
     * @param Route $route Route instance
     * @return void
     */
    public static function register(Route $route)
    {
        $route->prefix('universal-analytics', function (Route $route) {
            $categories = new CategoriesController();
            $metrics = new MetricsController();
            $sources = new SourcesController();
            $data = new DataController();
            $dashboards = new DashboardsController();
            $system = new SystemController();

            // ==========================================
            // CATEGORIES
            // ==========================================

            $route->get('categories', [$categories, 'get_categories'],
                RouteAuthMiddleware::authenticated());

            $route->get('categories/{slug}', [$categories, 'get_category'],
                RouteAuthMiddleware::authenticated());

            // ==========================================
            // METRICS
            // ==========================================

            $route->get('metrics', [$metrics, 'get_all_metrics'],
                RouteAuthMiddleware::authenticated());

            $route->get('metrics/category/{category_slug}', [$metrics, 'get_metrics_by_category'],
                RouteAuthMiddleware::authenticated());

            $route->get('metrics/{slug}', [$metrics, 'get_metric'],
                RouteAuthMiddleware::authenticated());

            // ==========================================
            // DATA SOURCES
            // ==========================================

            $route->get('sources', [$sources, 'get_data_sources'],
                RouteAuthMiddleware::authenticated());

            $route->get('sources/{slug}', [$sources, 'get_data_source'],
                RouteAuthMiddleware::authenticated());

            $route->get('sources/{source_slug}/metrics', [$sources, 'get_source_metrics'],
                RouteAuthMiddleware::authenticated());

            // ==========================================
            // METRIC DATA
            // ==========================================

            $route->get('metric-data', [$data, 'get_metric_data'],
                RouteAuthMiddleware::authenticated());

            $route->get('multiple-metrics-data', [$data, 'get_multiple_metrics_data'],
                RouteAuthMiddleware::authenticated());

            // ==========================================
            // DASHBOARDS
            // ==========================================

            $route->get('dashboard-templates', [$dashboards, 'get_dashboard_templates'],
                RouteAuthMiddleware::authenticated());

            $route->get('user-dashboards', [$dashboards, 'get_user_dashboards'],
                RouteAuthMiddleware::authenticated());

            $route->post('user-dashboards', [$dashboards, 'save_user_dashboard'],
                RouteAuthMiddleware::authenticated());

            // ==========================================
            // SYSTEM
            // ==========================================

            $route->get('system-stats', [$system, 'get_system_stats'],
                RouteAuthMiddleware::authenticated());

            $route->post('install', [$system, 'install_system'],
                RouteAuthMiddleware::admin());
        });
    }
}
