"""HTTP client for the approvals API."""

from __future__ import annotations

from peon_mcp.common.base_client import BaseAPIClient


class ApprovalsClient(BaseAPIClient):
    async def create_approval(
        self,
        title: str,
        options: list[str],
        *,
        agent_session_id: int | None = None,
        task_id: int | None = None,
        context: str = "",
        priority: str = "medium",
    ) -> dict | str:
        return await self._request(
            "POST",
            "/api/approvals",
            json={
                "title": title,
                "options": options,
                "agent_session_id": agent_session_id,
                "task_id": task_id,
                "context": context,
                "priority": priority,
            },
        )

    async def list_approvals(
        self,
        *,
        agent_session_id: int | None = None,
        task_id: int | None = None,
        status: str | None = None,
        limit: int = 50,
        offset: int = 0,
    ) -> dict | str:
        return await self._request(
            "GET",
            "/api/approvals",
            params={
                "agent_session_id": agent_session_id,
                "task_id": task_id,
                "status": status,
                "limit": limit,
                "offset": offset,
            },
        )

    async def get_approval(self, approval_id: str) -> dict | str:
        return await self._request("GET", f"/api/approvals/{approval_id}")

    async def respond_approval(
        self,
        approval_id: str,
        response: str,
        status: str,
    ) -> dict | str:
        return await self._request(
            "PATCH",
            f"/api/approvals/{approval_id}",
            json={"response": response, "status": status},
        )
