import datetime

from fastapi import APIRouter

from gallery.easel.core import AppRequest
from gallery.sketch.weather.model import Location, WeatherResponse

router = APIRouter(prefix="/weather")


@router.get("/providers")
async def get_api_weather_providers(request: AppRequest) -> list[str]:
    return request.app.state.api.get_api_providers("weather")


@router.get("/locations")
async def get_api_weather_locations(request: AppRequest, query: str) -> list[Location]:
    weather_api = request.app.state.api.weather
    return await weather_api.find_locations(query)


@router.get("/{location}/day/{date}")
async def get_api_weather_day(request: AppRequest, location: str, date: datetime.date) -> WeatherResponse:
    weather_api = request.app.state.api.weather
    return await weather_api.get_day(location, date)


@router.get("/{location}/days/{days}")
async def get_api_weather_days(request: AppRequest, location: str, days: int) -> WeatherResponse:
    weather_api = request.app.state.api.weather
    return await weather_api.get_days(location, days)
