# 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.dismiss_terminal_action_response import DismissTerminalActionResponse
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.dismiss_terminal_checkout_response import DismissTerminalCheckoutResponse
from ..types.dismiss_terminal_refund_response import DismissTerminalRefundResponse
from ..core.client_wrapper import AsyncClientWrapper
from ..core.http_response import AsyncHttpResponse


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

    def dismiss_terminal_action(
        self, action_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DismissTerminalActionResponse]:
        """
        Dismisses a Terminal action request if the status and type of the request permits it.

        See [Link and Dismiss Actions](https://developer.squareup.com/docs/terminal-api/advanced-features/custom-workflows/link-and-dismiss-actions) for more details.

        Parameters
        ----------
        action_id : str
            Unique ID for the `TerminalAction` associated with the action to be dismissed.

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

        Returns
        -------
        HttpResponse[DismissTerminalActionResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/terminals/actions/{jsonable_encoder(action_id)}/dismiss",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DismissTerminalActionResponse,
                    construct_type(
                        type_=DismissTerminalActionResponse,  # 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 dismiss_terminal_checkout(
        self, checkout_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DismissTerminalCheckoutResponse]:
        """
        Dismisses a Terminal checkout request if the status and type of the request permits it.

        Parameters
        ----------
        checkout_id : str
            Unique ID for the `TerminalCheckout` associated with the checkout to be dismissed.

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

        Returns
        -------
        HttpResponse[DismissTerminalCheckoutResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/terminals/checkouts/{jsonable_encoder(checkout_id)}/dismiss",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DismissTerminalCheckoutResponse,
                    construct_type(
                        type_=DismissTerminalCheckoutResponse,  # 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 dismiss_terminal_refund(
        self, terminal_refund_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[DismissTerminalRefundResponse]:
        """
        Dismisses a Terminal refund request if the status and type of the request permits it.

        Parameters
        ----------
        terminal_refund_id : str
            Unique ID for the `TerminalRefund` associated with the refund to be dismissed.

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

        Returns
        -------
        HttpResponse[DismissTerminalRefundResponse]
            Success
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v2/terminals/refunds/{jsonable_encoder(terminal_refund_id)}/dismiss",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DismissTerminalRefundResponse,
                    construct_type(
                        type_=DismissTerminalRefundResponse,  # 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 AsyncRawTerminalClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def dismiss_terminal_action(
        self, action_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DismissTerminalActionResponse]:
        """
        Dismisses a Terminal action request if the status and type of the request permits it.

        See [Link and Dismiss Actions](https://developer.squareup.com/docs/terminal-api/advanced-features/custom-workflows/link-and-dismiss-actions) for more details.

        Parameters
        ----------
        action_id : str
            Unique ID for the `TerminalAction` associated with the action to be dismissed.

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

        Returns
        -------
        AsyncHttpResponse[DismissTerminalActionResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/terminals/actions/{jsonable_encoder(action_id)}/dismiss",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DismissTerminalActionResponse,
                    construct_type(
                        type_=DismissTerminalActionResponse,  # 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 dismiss_terminal_checkout(
        self, checkout_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DismissTerminalCheckoutResponse]:
        """
        Dismisses a Terminal checkout request if the status and type of the request permits it.

        Parameters
        ----------
        checkout_id : str
            Unique ID for the `TerminalCheckout` associated with the checkout to be dismissed.

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

        Returns
        -------
        AsyncHttpResponse[DismissTerminalCheckoutResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/terminals/checkouts/{jsonable_encoder(checkout_id)}/dismiss",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DismissTerminalCheckoutResponse,
                    construct_type(
                        type_=DismissTerminalCheckoutResponse,  # 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 dismiss_terminal_refund(
        self, terminal_refund_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[DismissTerminalRefundResponse]:
        """
        Dismisses a Terminal refund request if the status and type of the request permits it.

        Parameters
        ----------
        terminal_refund_id : str
            Unique ID for the `TerminalRefund` associated with the refund to be dismissed.

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

        Returns
        -------
        AsyncHttpResponse[DismissTerminalRefundResponse]
            Success
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v2/terminals/refunds/{jsonable_encoder(terminal_refund_id)}/dismiss",
            method="POST",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    DismissTerminalRefundResponse,
                    construct_type(
                        type_=DismissTerminalRefundResponse,  # 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)
