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


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

    def list(self, project_id: str = None, status: str = None,
             page: int = 1, page_size: int = 20) -> Dict[str, Any]:
        params = {"page": page, "pageSize": page_size}
        if project_id:
            params["projectId"] = project_id
        if status:
            params["status"] = status
        return self._http.get("/devices", params=params)

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

    def create(self, data: Dict[str, Any]) -> Dict[str, Any]:
        return self._http.post("/devices", json=data)

    def update(self, device_id: str, data: Dict[str, Any]) -> Dict[str, Any]:
        return self._http.patch(f"/devices/{device_id}", json=data)

    def delete(self, device_id: str) -> None:
        return self._http.delete(f"/devices/{device_id}")

    def activate(self, device_id: str) -> Dict[str, Any]:
        return self._http.post(f"/devices/{device_id}/activate")

    def deactivate(self, device_id: str) -> Dict[str, Any]:
        return self._http.post(f"/devices/{device_id}/deactivate")
