from .api import API, Api
from .schedule.api import ScheduleApi
from .weather.api import WeatherApi


class ApiBundle:
    def __init__(self, values: list[Api]):
        self._values = values
        self._by_provider = {value.provider: value for value in values}

    def get_api_providers(self, api_type: str) -> list[str]:
        result = []
        for value in self._values:
            if value.type == api_type:
                result.append(value.provider)
        return result

    def get_api(self, api_type: type[API], provider: str | None = None) -> API:
        for value in self._values:
            if isinstance(value, api_type):
                if provider is None or provider == value.provider:
                    return value
        raise ValueError(api_type, provider)

    def get_weather(self, provider: str | None = None) -> WeatherApi:
        return self.get_api(WeatherApi, provider)

    def get_schedule(self, provider: str | None = None) -> ScheduleApi:
        return self.get_api(ScheduleApi, provider)
