<?php

namespace MintyPHP\Support;

use MintyPHP\Support\Search\SearchItemMapperProvider;
use MintyPHP\Support\Search\SearchQueryNormalizer;
use MintyPHP\Support\Search\SearchSpecialResourceProvider;
use MintyPHP\Support\Search\SearchSqlResourceProvider;
use MintyPHP\Support\Search\SearchUiMetaProvider;

class SearchConfig
{
    public static function tenantScopeFilters(): array
    {
        return SearchSqlResourceProvider::tenantScopeFilters();
    }

    public static function resources(string $query, string $locale): array
    {
        return SearchSqlResourceProvider::resources($query, $locale);
    }

    public static function iconForKey(string $key): string
    {
        return SearchUiMetaProvider::iconForKey($key);
    }

    public static function listUrl(string $key, string $query): string
    {
        return SearchUiMetaProvider::listUrl($key, $query);
    }

    public static function mapPreviewItem(string $key, array $data, string $query): ?array
    {
        return SearchItemMapperProvider::mapPreviewItem($key, $data, $query);
    }

    public static function mapResultItem(string $key, string $label, array $data): ?array
    {
        return SearchItemMapperProvider::mapResultItem($key, $label, $data);
    }

    public static function hotkeyPreviewResource(string $query): ?array
    {
        return SearchSpecialResourceProvider::hotkeyPreviewResource($query);
    }

    public static function hotkeyResultItems(string $query): array
    {
        return SearchSpecialResourceProvider::hotkeyResultItems($query);
    }

    public static function docsPreviewResource(string $query): ?array
    {
        return SearchSpecialResourceProvider::docsPreviewResource($query);
    }

    public static function docsResultItems(string $query): array
    {
        return SearchSpecialResourceProvider::docsResultItems($query);
    }

    public static function normalizeScoreQuery(string $query): string
    {
        return SearchQueryNormalizer::normalizeScoreQuery($query);
    }

    /**
     * @return array{missingIcons: string[], missingListUrls: string[]}
     */
    public static function providerCoverageGaps(): array
    {
        $missingIcons = [];
        $missingListUrls = [];
        foreach (SearchSqlResourceProvider::resourceKeys() as $key) {
            if (!SearchUiMetaProvider::hasIconForKey($key)) {
                $missingIcons[] = $key;
            }
            if (!SearchUiMetaProvider::hasListUrlForKey($key)) {
                $missingListUrls[] = $key;
            }
        }

        return [
            'missingIcons' => $missingIcons,
            'missingListUrls' => $missingListUrls,
        ];
    }
}
