<?php

declare(strict_types=1);

namespace portalpeople\apidocs\services;

use Yii;

class DocumentationService
{
    /**
     * @param array<int, string> $scanDirs
     * @return array<string, mixed>
     */
    public function buildSwaggerActionsConfig(array $scanDirs, string $apiKey): array
    {
        return [
            'index' => [
                'class' => 'light\\swagger\\SwaggerAction',
                'restUrl' => \yii\helpers\Url::to(['/v1/documentation/docapi'], true),
            ],
            'docapi' => [
                'class' => 'light\\swagger\\SwaggerApiAction',
                'scanDir' => $scanDirs,
                'api_key' => $apiKey,
            ],
        ];
    }

    /**
     * @return \backend\models\Pagegroupbe|null
     */
    public function findPageByUrl(string $url)
    {
        return \backend\models\Pagegroupbe::find()->where(['url' => $url])->one();
    }
}
