<?php

namespace onespace\core\controllers;

use onespace\core\components\MetricsCollectorInterface;
use onespace\core\modules\metrics\actions\MetricsAction;
use yii\web\Controller;

/**
 * @psalm-api
 *
 * @template-extends Controller<\yii\base\Module>
 */
class MetricsController extends Controller
{
    public $enableCsrfValidation = false;

    /** @var string application component ID for the Prometheus registry */
    public string $metricsComponent = 'metrics';

    /**
     * @var array<class-string<MetricsCollectorInterface>|MetricsCollectorInterface|array>
     * Collectors run, in declared order, at scrape time before the
     * registry is rendered. Empty by default - configure explicitly,
     * either directly on this controller (e.g. via controllerMap) or, if
     * this controller is reached through onespace\core\modules\metrics\Module,
     * via that module's `collectors` setting.
     */
    public array $collectors = [];

    #[\Override]
    public function actions(): array
    {
        return [
            'index' => [
                'class'            => MetricsAction::class,
                'metricsComponent' => $this->metricsComponent,
                'collectors'       => $this->collectors,
            ],
        ];
    }
}