from typing import Dict, Any, Optional
from ..http_client import HTTPClient


class TelemetryResource:
    def __init__(self, http: HTTPClient):
        self._http = http

    def list(self, device_id: str, start_date: str = None, end_date: str = None,
             page: int = 1, page_size: int = 100) -> Dict[str, Any]:
        params = {"deviceId": device_id, "page": page, "pageSize": page_size}
        if start_date:
            params["startDate"] = start_date
        if end_date:
            params["endDate"] = end_date
        return self._http.get("/telemetry", params=params)

    def get_latest(self, device_id: str) -> Dict[str, Any]:
        return self._http.get(f"/telemetry/devices/{device_id}/latest")
