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

import typing
from ..core.client_wrapper import SyncClientWrapper
from .raw_client import RawV1TransactionsClient
from ..types.sort_order import SortOrder
from ..core.request_options import RequestOptions
from ..types.v1order import V1Order
from ..types.v1update_order_request_action import V1UpdateOrderRequestAction
from ..core.client_wrapper import AsyncClientWrapper
from .raw_client import AsyncRawV1TransactionsClient

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class V1TransactionsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawV1TransactionsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawV1TransactionsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawV1TransactionsClient
        """
        return self._raw_client

    def v1list_orders(
        self,
        location_id: str,
        *,
        order: typing.Optional[SortOrder] = None,
        limit: typing.Optional[int] = None,
        batch_token: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[V1Order]:
        """
        Provides summary information for a merchant's online store orders.

        Parameters
        ----------
        location_id : str
            The ID of the location to list online store orders for.

        order : typing.Optional[SortOrder]
            The order in which payments are listed in the response.

        limit : typing.Optional[int]
            The maximum number of payments to return in a single response. This value cannot exceed 200.

        batch_token : typing.Optional[str]
            A pagination cursor to retrieve the next set of results for your
            original query to the endpoint.

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

        Returns
        -------
        typing.List[V1Order]
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.v1transactions.v1list_orders(
            location_id="location_id",
        )
        """
        response = self._raw_client.v1list_orders(
            location_id, order=order, limit=limit, batch_token=batch_token, request_options=request_options
        )
        return response.data

    def v1retrieve_order(
        self, location_id: str, order_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> V1Order:
        """
        Provides comprehensive information for a single online store order, including the order's history.

        Parameters
        ----------
        location_id : str
            The ID of the order's associated location.

        order_id : str
            The order's Square-issued ID. You obtain this value from Order objects returned by the List Orders endpoint

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

        Returns
        -------
        V1Order
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.v1transactions.v1retrieve_order(
            location_id="location_id",
            order_id="order_id",
        )
        """
        response = self._raw_client.v1retrieve_order(location_id, order_id, request_options=request_options)
        return response.data

    def v1update_order(
        self,
        location_id: str,
        order_id: str,
        *,
        action: V1UpdateOrderRequestAction,
        shipped_tracking_number: typing.Optional[str] = OMIT,
        completed_note: typing.Optional[str] = OMIT,
        refunded_note: typing.Optional[str] = OMIT,
        canceled_note: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> V1Order:
        """
        Updates the details of an online store order. Every update you perform on an order corresponds to one of three actions:

        Parameters
        ----------
        location_id : str
            The ID of the order's associated location.

        order_id : str
            The order's Square-issued ID. You obtain this value from Order objects returned by the List Orders endpoint

        action : V1UpdateOrderRequestAction
            The action to perform on the order (COMPLETE, CANCEL, or REFUND).
            See [V1UpdateOrderRequestAction](#type-v1updateorderrequestaction) for possible values

        shipped_tracking_number : typing.Optional[str]
            The tracking number of the shipment associated with the order. Only valid if action is COMPLETE.

        completed_note : typing.Optional[str]
            A merchant-specified note about the completion of the order. Only valid if action is COMPLETE.

        refunded_note : typing.Optional[str]
            A merchant-specified note about the refunding of the order. Only valid if action is REFUND.

        canceled_note : typing.Optional[str]
            A merchant-specified note about the canceling of the order. Only valid if action is CANCEL.

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

        Returns
        -------
        V1Order
            Success

        Examples
        --------
        from square import Square

        client = Square(
            token="YOUR_TOKEN",
        )
        client.v1transactions.v1update_order(
            location_id="location_id",
            order_id="order_id",
            action="COMPLETE",
        )
        """
        response = self._raw_client.v1update_order(
            location_id,
            order_id,
            action=action,
            shipped_tracking_number=shipped_tracking_number,
            completed_note=completed_note,
            refunded_note=refunded_note,
            canceled_note=canceled_note,
            request_options=request_options,
        )
        return response.data


class AsyncV1TransactionsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawV1TransactionsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawV1TransactionsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawV1TransactionsClient
        """
        return self._raw_client

    async def v1list_orders(
        self,
        location_id: str,
        *,
        order: typing.Optional[SortOrder] = None,
        limit: typing.Optional[int] = None,
        batch_token: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[V1Order]:
        """
        Provides summary information for a merchant's online store orders.

        Parameters
        ----------
        location_id : str
            The ID of the location to list online store orders for.

        order : typing.Optional[SortOrder]
            The order in which payments are listed in the response.

        limit : typing.Optional[int]
            The maximum number of payments to return in a single response. This value cannot exceed 200.

        batch_token : typing.Optional[str]
            A pagination cursor to retrieve the next set of results for your
            original query to the endpoint.

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

        Returns
        -------
        typing.List[V1Order]
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.v1transactions.v1list_orders(
                location_id="location_id",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.v1list_orders(
            location_id, order=order, limit=limit, batch_token=batch_token, request_options=request_options
        )
        return response.data

    async def v1retrieve_order(
        self, location_id: str, order_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> V1Order:
        """
        Provides comprehensive information for a single online store order, including the order's history.

        Parameters
        ----------
        location_id : str
            The ID of the order's associated location.

        order_id : str
            The order's Square-issued ID. You obtain this value from Order objects returned by the List Orders endpoint

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

        Returns
        -------
        V1Order
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.v1transactions.v1retrieve_order(
                location_id="location_id",
                order_id="order_id",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.v1retrieve_order(location_id, order_id, request_options=request_options)
        return response.data

    async def v1update_order(
        self,
        location_id: str,
        order_id: str,
        *,
        action: V1UpdateOrderRequestAction,
        shipped_tracking_number: typing.Optional[str] = OMIT,
        completed_note: typing.Optional[str] = OMIT,
        refunded_note: typing.Optional[str] = OMIT,
        canceled_note: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> V1Order:
        """
        Updates the details of an online store order. Every update you perform on an order corresponds to one of three actions:

        Parameters
        ----------
        location_id : str
            The ID of the order's associated location.

        order_id : str
            The order's Square-issued ID. You obtain this value from Order objects returned by the List Orders endpoint

        action : V1UpdateOrderRequestAction
            The action to perform on the order (COMPLETE, CANCEL, or REFUND).
            See [V1UpdateOrderRequestAction](#type-v1updateorderrequestaction) for possible values

        shipped_tracking_number : typing.Optional[str]
            The tracking number of the shipment associated with the order. Only valid if action is COMPLETE.

        completed_note : typing.Optional[str]
            A merchant-specified note about the completion of the order. Only valid if action is COMPLETE.

        refunded_note : typing.Optional[str]
            A merchant-specified note about the refunding of the order. Only valid if action is REFUND.

        canceled_note : typing.Optional[str]
            A merchant-specified note about the canceling of the order. Only valid if action is CANCEL.

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

        Returns
        -------
        V1Order
            Success

        Examples
        --------
        import asyncio

        from square import AsyncSquare

        client = AsyncSquare(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.v1transactions.v1update_order(
                location_id="location_id",
                order_id="order_id",
                action="COMPLETE",
            )


        asyncio.run(main())
        """
        response = await self._raw_client.v1update_order(
            location_id,
            order_id,
            action=action,
            shipped_tracking_number=shipped_tracking_number,
            completed_note=completed_note,
            refunded_note=refunded_note,
            canceled_note=canceled_note,
            request_options=request_options,
        )
        return response.data
