"""Weather data resource for the Daly Energy SDK.

Weather data contains irradiance, temperature, and wind arrays used by
the energy production model.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from dalysdk.client import DalyClient


class WeatherDataResource:
    """Interact with the ``/weatherdata`` endpoints.

    Usage::

        weather_list = client.weather_data.list()
        weather = client.weather_data.get(1)
        new_wd = client.weather_data.create({...})
        client.weather_data.delete(1)
    """

    def __init__(self, client: DalyClient):
        self._client = client

    def list(self) -> list[dict]:
        """List all weather data records in the workspace.

        Returns:
            List of weather data dicts (without the large array payloads).
        """
        return self._client._request("GET", "/weatherdata")

    def get(self, weather_data_id: int) -> dict:
        """Get a weather data record by its workspace-scoped ID.

        Includes full weather arrays.

        Args:
            weather_data_id: Workspace-scoped weather data index.

        Returns:
            Weather data dict with arrays.

        Raises:
            NotFoundError: If the weather data does not exist.
        """
        return self._client._request("GET", f"/weatherdata/{weather_data_id}")

    def create(self, data: dict) -> dict:
        """Create a weather data record.

        Args:
            data: Weather data payload. Typically includes ``name``,
                  ``locationId`` (or ``internallocationid``), and weather
                  arrays (GHI, DNI, DHI, temperature, wind speed, etc.).

        Returns:
            Created weather data dict (includes assigned IDs).
        """
        return self._client._request("POST", "/weatherdata", json=data)

    def delete(self, weather_data_id: int) -> dict:
        """Delete a weather data record.

        Args:
            weather_data_id: Workspace-scoped weather data index.

        Returns:
            Confirmation dict (``{"deleted": True}``).

        Raises:
            NotFoundError: If the weather data does not exist.
        """
        return self._client._request("DELETE", f"/weatherdata/{weather_data_id}")
