from collections import defaultdict

from .api import API, Api


class ApiBundle:
    def __init__(self, values: list[Api]):
        self._values = values
        self._providers_by_api = defaultdict(list)
        self._api_map = {}
        for value in self._values:
            self._providers_by_api[value.type].append(value.provider)
            self._api_map[(value.type, value.provider)] = value

    def get_api_providers(self, api_type: type[API]) -> list[str]:
        return self._providers_by_api[api_type.TYPE]

    def get_api(self, api_type: type[API], provider: str) -> API:
        return self._api_map[(api_type.TYPE, provider)]
