import { readKey } from "../../http"; import type { WeatherProvider } from "../../types"; import { getFreeForecast } from "./free"; import { getOneCallForecast } from "./onecall"; /** * OpenWeather (the default provider). * * Set OPENWEATHER_PLAN in .env.local: * free (default) → 5 days in 3-hour steps * onecall → One Call 4.0: 48 hours hourly + daily, plus dew point and UV */ const usesOneCall = () => process.env.OPENWEATHER_PLAN === "onecall"; export const openWeather: WeatherProvider = { id: "openweather", label: "OpenWeather", envKey: "OPENWEATHER_API_KEY", limits: () => (usesOneCall() ? { forecastDays: 8, hourlyStepHours: 1 } : { forecastDays: 5, hourlyStepHours: 3 }), getForecast(lat, lon) { const key = readKey("OPENWEATHER_API_KEY"); return usesOneCall() ? getOneCallForecast(lat, lon, key) : getFreeForecast(lat, lon, key); }, };