import type { WeatherData } from '../types';

export const getWeatherData = async (lat: number, lon: number): Promise<WeatherData | null> => {
  const apiKey = '335799082893fad97fa36118b131f919';
  const url = `https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}&units=metric`;

  try {
    const response = await fetch(url);
    const data = await response.json();
    return {
      windSpeed: data.wind.speed,
      windAngle: data.wind.deg,
    };
  } catch {
    return null;
  }
};
