"""HTTP client methods for the leads domain."""

from __future__ import annotations

from peon_mcp.common.base_client import BaseAPIClient


class LeadsAPIClient(BaseAPIClient):
    """Client methods for leads endpoints."""

    async def list_leads(
        self,
        project_id: str,
        status: str | None = None,
        source: str | None = None,
        created_after: str | None = None,
        created_before: str | None = None,
        limit: int = 50,
        offset: int = 0,
    ) -> dict:
        owner, repo = project_id.split("/", 1)
        return await self._request(
            "GET",
            f"/api/projects/{owner}/{repo}/leads",
            params={
                "status": status,
                "source": source,
                "created_after": created_after,
                "created_before": created_before,
                "limit": limit,
                "offset": offset,
            },
        )

    async def create_lead(self, project_id: str, **kwargs) -> dict:
        owner, repo = project_id.split("/", 1)
        return await self._request(
            "POST",
            f"/api/projects/{owner}/{repo}/leads",
            json=kwargs,
        )

    async def get_lead(self, project_id: str, lead_id: str) -> dict:
        owner, repo = project_id.split("/", 1)
        return await self._request(
            "GET",
            f"/api/projects/{owner}/{repo}/leads/{lead_id}",
        )

    async def update_lead(self, project_id: str, lead_id: str, **kwargs) -> dict:
        owner, repo = project_id.split("/", 1)
        return await self._request(
            "PATCH",
            f"/api/projects/{owner}/{repo}/leads/{lead_id}",
            json=kwargs,
        )

    async def delete_lead(self, project_id: str, lead_id: str) -> dict:
        owner, repo = project_id.split("/", 1)
        return await self._request(
            "DELETE",
            f"/api/projects/{owner}/{repo}/leads/{lead_id}",
        )
