"""AgentBill Raw Response Wrapper — v10.3.0

Provides the `.with_raw_response` pattern for resource classes.
Instead of returning parsed data, returns the full AgentBillResponse
with .status, .headers, .data, and .ok.

Usage:
    response = client.customers.with_raw_response.list(limit=10)
    print(response.status)   # 200
    print(response.headers)  # {"x-request-id": "..."}
    print(response.data)     # parsed JSON
"""

from typing import Any, Dict, Optional

from .http_client import AgentBillHTTPClient, AgentBillResponse


class RawResponseProxy:
    """Proxy that wraps a resource and returns raw AgentBillResponse objects.

    Every method call goes through the shared HTTP client but returns
    the full response wrapper instead of just .data.
    """

    def __init__(self, http_client: AgentBillHTTPClient, base_path: str):
        self._http = http_client
        self._base_path = base_path

    def list(self, **params) -> AgentBillResponse:
        str_params = {k: str(v) for k, v in params.items() if v is not None}
        return self._http.get(self._base_path, params=str_params)

    def create(self, **payload) -> AgentBillResponse:
        clean = {k: v for k, v in payload.items() if v is not None}
        return self._http.post(self._base_path, json=clean)

    def get(self, resource_id: str) -> AgentBillResponse:
        return self._http.get(self._base_path, params={"id": resource_id})

    def update(self, resource_id: str, **payload) -> AgentBillResponse:
        clean = {k: v for k, v in payload.items() if v is not None}
        clean["id"] = resource_id
        return self._http.patch(self._base_path, json=clean)

    def delete(self, resource_id: str) -> AgentBillResponse:
        return self._http.request("DELETE", self._base_path, json={"id": resource_id})


class WithRawResponseMixin:
    """Mixin that adds .with_raw_response to any resource class."""

    _http: AgentBillHTTPClient
    _resource_path: str = ""

    @property
    def with_raw_response(self) -> RawResponseProxy:
        """Return a proxy that gives full HTTP response objects.

        Example:
            resp = client.customers.with_raw_response.list(limit=10)
            print(resp.status)   # 200
            print(resp.headers)  # dict
            print(resp.data)     # parsed JSON
            print(resp.ok)       # True
        """
        return RawResponseProxy(self._http, self._resource_path)


__all__ = ["RawResponseProxy", "WithRawResponseMixin"]
