# This file was auto-generated by Fern from our API Definition.

from ...core.client_wrapper import SyncClientWrapper
import typing
from ...core.request_options import RequestOptions
from ...core.http_response import HttpResponse
from ...types.get_dispute_evidence_response import GetDisputeEvidenceResponse
from ...core.jsonable_encoder import jsonable_encoder
from ...core.unchecked_base_model import construct_type
from json.decoder import JSONDecodeError
from ...core.api_error import ApiError
from ...types.delete_dispute_evidence_response import DeleteDisputeEvidenceResponse
from ...core.client_wrapper import AsyncClientWrapper
from ...core.http_response import AsyncHttpResponse


class RawEvidenceClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def get(
        self, dispute_id: str, evidence_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[GetDisputeEvidenceResponse]:
        """
        Returns the metadata for the evidence specified in the request URL path.

        You must maintain a copy of any evidence uploaded if you want to reference it later. Evidence cannot be downloaded after you upload it.

        Parameters
        ----------
        dispute_id : str
            The ID of the dispute from which you want to retrieve evidence metadata.

        evidence_id : str
            The ID of the evidence to retrieve.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[GetDisputeEvidenceResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/disputes/{jsonable_encoder(dispute_id)}/evidence/{jsonable_encoder(evidence_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetDisputeEvidenceResponse,
                    construct_type(
                        type_=GetDisputeEvidenceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def delete(
        self, dispute_id: str, evidence_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DeleteDisputeEvidenceResponse]:
        """
        Removes specified evidence from a dispute.
        Square does not send the bank any evidence that is removed.

        Parameters
        ----------
        dispute_id : str
            The ID of the dispute from which you want to remove evidence.

        evidence_id : str
            The ID of the evidence you want to remove.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[DeleteDisputeEvidenceResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/disputes/{jsonable_encoder(dispute_id)}/evidence/{jsonable_encoder(evidence_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteDisputeEvidenceResponse,
                    construct_type(
                        type_=DeleteDisputeEvidenceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncRawEvidenceClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get(
        self, dispute_id: str, evidence_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[GetDisputeEvidenceResponse]:
        """
        Returns the metadata for the evidence specified in the request URL path.

        You must maintain a copy of any evidence uploaded if you want to reference it later. Evidence cannot be downloaded after you upload it.

        Parameters
        ----------
        dispute_id : str
            The ID of the dispute from which you want to retrieve evidence metadata.

        evidence_id : str
            The ID of the evidence to retrieve.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[GetDisputeEvidenceResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/disputes/{jsonable_encoder(dispute_id)}/evidence/{jsonable_encoder(evidence_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    GetDisputeEvidenceResponse,
                    construct_type(
                        type_=GetDisputeEvidenceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def delete(
        self, dispute_id: str, evidence_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DeleteDisputeEvidenceResponse]:
        """
        Removes specified evidence from a dispute.
        Square does not send the bank any evidence that is removed.

        Parameters
        ----------
        dispute_id : str
            The ID of the dispute from which you want to remove evidence.

        evidence_id : str
            The ID of the evidence you want to remove.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[DeleteDisputeEvidenceResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/disputes/{jsonable_encoder(dispute_id)}/evidence/{jsonable_encoder(evidence_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DeleteDisputeEvidenceResponse,
                    construct_type(
                        type_=DeleteDisputeEvidenceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
