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


class ApiBundle(list[Api]):
    def __init__(self, values: list[Api]) -> None:
        super().__init__(values)

    def get_api_by_provider(self, provider: str) -> Api:
        for value in self:
            if value.PROVIDER == provider:
                return value
        raise ValueError(provider)

    def get_api_by_type(self, api_type: type[API]) -> API:
        for value in self:
            if isinstance(value, api_type):
                return value
        raise ValueError(api_type)

    @property
    def weather(self) -> WeatherApi:
        return self.get_api_by_type(WeatherApi)

    @property
    def schedule(self) -> ScheduleApi:
        return self.get_api_by_type(ScheduleApi)
