# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import List, Union
from datetime import date
from typing_extensions import Literal

import httpx

from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ....._utils import maybe_transform, async_maybe_transform
from ....._compat import cached_property
from ....._resource import SyncAPIResource, AsyncAPIResource
from ....._response import (
    to_raw_response_wrapper,
    to_streamed_response_wrapper,
    async_to_raw_response_wrapper,
    async_to_streamed_response_wrapper,
)
from ....._base_client import make_request_options
from .....types.api.v2.shows import showtime_list_params, showtime_retrieve_sections_params
from .....types.api.v2.shows.showtime_list_response import ShowtimeListResponse
from .....types.api.v2.shows.showtime_retrieve_sections_response import ShowtimeRetrieveSectionsResponse
from .....types.api.v2.shows.showtime_retrieve_inventory_items_response import ShowtimeRetrieveInventoryItemsResponse
from .....types.api.v2.shows.showtime_retrieve_with_rush_availability_response import (
    ShowtimeRetrieveWithRushAvailabilityResponse,
)

__all__ = ["ShowtimesResource", "AsyncShowtimesResource"]


class ShowtimesResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> ShowtimesResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/alisytsma/ali-test-mcp#accessing-raw-response-data-eg-headers
        """
        return ShowtimesResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> ShowtimesResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/alisytsma/ali-test-mcp#with_streaming_response
        """
        return ShowtimesResourceWithStreamingResponse(self)

    def list(
        self,
        show_id: int,
        *,
        end_date: Union[str, date] | NotGiven = NOT_GIVEN,
        include_no_inventory: str | NotGiven = NOT_GIVEN,
        max_price: float | NotGiven = NOT_GIVEN,
        min_price: float | NotGiven = NOT_GIVEN,
        quantity: int | NotGiven = NOT_GIVEN,
        start_date: Union[str, date] | NotGiven = NOT_GIVEN,
        ticket_type: str | NotGiven = NOT_GIVEN,
        use_override_fields: bool | NotGiven = NOT_GIVEN,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeListResponse:
        """
        Get list of all UPCOMING showtimes for show.

        Args:
          end_date: end date to filter showtimes

          include_no_inventory: When true, includes showtimes with no inventory in the response.

          max_price: A monetary amount with 2 decimal places of precision. This allows to filter
              showtimes where seats with price less than this value are present.

          min_price: A monetary amount with 2 decimal places of precision. This allows to filter
              showtimes where seats with price more than this value are present.

          quantity: For showtimes endpoint: Quantity allows filtering showtimes which have
              maxContiguousSeats greater or equal than `quantity`. Only applicable when
              listingType=`REGULAR`

              For showtimes/{showtime_id}/seats: Quantity allows to filter all seatblocks
              which have number of seats greater than or equal to `quantity`.

          start_date: start date to filter showtimes

          ticket_type: One of '#/definitions/TicketType'

          use_override_fields: When true, uses override regular ticket values for the showtime availabilities
              if they exist.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return self._get(
            f"/api/v2/shows/{show_id}/showtimes",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "end_date": end_date,
                        "include_no_inventory": include_no_inventory,
                        "max_price": max_price,
                        "min_price": min_price,
                        "quantity": quantity,
                        "start_date": start_date,
                        "ticket_type": ticket_type,
                        "use_override_fields": use_override_fields,
                    },
                    showtime_list_params.ShowtimeListParams,
                ),
            ),
            cast_to=ShowtimeListResponse,
        )

    def retrieve_inventory_items(
        self,
        showtime_id: int,
        *,
        show_id: int,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeRetrieveInventoryItemsResponse:
        """
        Get list of InventoryItem for this showtime.

        InventoryItem is combination of section, price and discount.

        Client need to group all Inventory Items by section_price_discount and order by
        orderNum, ASC, and then by price, DESC.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return self._get(
            f"/api/v2/shows/{show_id}/showtimes/{showtime_id}/inventoryItems",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ShowtimeRetrieveInventoryItemsResponse,
        )

    def retrieve_sections(
        self,
        showtime_id: int,
        *,
        id: int,
        chart_key_override: str | NotGiven = NOT_GIVEN,
        include_attributes: bool | NotGiven = NOT_GIVEN,
        max_seats: int | NotGiven = NOT_GIVEN,
        quantity: int | NotGiven = NOT_GIVEN,
        remove_unavailable_seats: bool | NotGiven = NOT_GIVEN,
        sort_by: List[Literal["NAME"]] | NotGiven = NOT_GIVEN,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeRetrieveSectionsResponse:
        """
        Get list of AssignedSection or GASection for this showtime.

        Args:
          chart_key_override: Optional chart key to override the show chart key for this showtime. Should only
              be used in special cases.

          include_attributes: Optional flag to include seat and section attributes

          max_seats: If more than this many seats are available, return this many at a maximum.
              Otherwise, return all available.

          quantity: For showtimes endpoint: Quantity allows filtering showtimes which have
              maxContiguousSeats greater or equal than `quantity`. Only applicable when
              listingType=`REGULAR`

              For showtimes/{showtime_id}/seats: Quantity allows to filter all seatblocks
              which have number of seats greater than or equal to `quantity`.

          remove_unavailable_seats: Optional flag to remove from response the unavailable seats present in redis
              state

          sort_by: List of sorting parameters (strings)

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return self._get(
            f"/api/v2/shows/{id}/showtimes/{showtime_id}/sections",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "chart_key_override": chart_key_override,
                        "include_attributes": include_attributes,
                        "max_seats": max_seats,
                        "quantity": quantity,
                        "remove_unavailable_seats": remove_unavailable_seats,
                        "sort_by": sort_by,
                    },
                    showtime_retrieve_sections_params.ShowtimeRetrieveSectionsParams,
                ),
            ),
            cast_to=ShowtimeRetrieveSectionsResponse,
        )

    def retrieve_with_rush_availability(
        self,
        show_id: int,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeRetrieveWithRushAvailabilityResponse:
        """
        Get list of all UPCOMING showtimes for show that have rush tickets available.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return self._get(
            f"/api/v2/shows/{show_id}/showtimes/with_rush_availability",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ShowtimeRetrieveWithRushAvailabilityResponse,
        )


class AsyncShowtimesResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncShowtimesResourceWithRawResponse:
        """
        This property can be used as a prefix for any HTTP method call to return
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/alisytsma/ali-test-mcp#accessing-raw-response-data-eg-headers
        """
        return AsyncShowtimesResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncShowtimesResourceWithStreamingResponse:
        """
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/alisytsma/ali-test-mcp#with_streaming_response
        """
        return AsyncShowtimesResourceWithStreamingResponse(self)

    async def list(
        self,
        show_id: int,
        *,
        end_date: Union[str, date] | NotGiven = NOT_GIVEN,
        include_no_inventory: str | NotGiven = NOT_GIVEN,
        max_price: float | NotGiven = NOT_GIVEN,
        min_price: float | NotGiven = NOT_GIVEN,
        quantity: int | NotGiven = NOT_GIVEN,
        start_date: Union[str, date] | NotGiven = NOT_GIVEN,
        ticket_type: str | NotGiven = NOT_GIVEN,
        use_override_fields: bool | NotGiven = NOT_GIVEN,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeListResponse:
        """
        Get list of all UPCOMING showtimes for show.

        Args:
          end_date: end date to filter showtimes

          include_no_inventory: When true, includes showtimes with no inventory in the response.

          max_price: A monetary amount with 2 decimal places of precision. This allows to filter
              showtimes where seats with price less than this value are present.

          min_price: A monetary amount with 2 decimal places of precision. This allows to filter
              showtimes where seats with price more than this value are present.

          quantity: For showtimes endpoint: Quantity allows filtering showtimes which have
              maxContiguousSeats greater or equal than `quantity`. Only applicable when
              listingType=`REGULAR`

              For showtimes/{showtime_id}/seats: Quantity allows to filter all seatblocks
              which have number of seats greater than or equal to `quantity`.

          start_date: start date to filter showtimes

          ticket_type: One of '#/definitions/TicketType'

          use_override_fields: When true, uses override regular ticket values for the showtime availabilities
              if they exist.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return await self._get(
            f"/api/v2/shows/{show_id}/showtimes",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "end_date": end_date,
                        "include_no_inventory": include_no_inventory,
                        "max_price": max_price,
                        "min_price": min_price,
                        "quantity": quantity,
                        "start_date": start_date,
                        "ticket_type": ticket_type,
                        "use_override_fields": use_override_fields,
                    },
                    showtime_list_params.ShowtimeListParams,
                ),
            ),
            cast_to=ShowtimeListResponse,
        )

    async def retrieve_inventory_items(
        self,
        showtime_id: int,
        *,
        show_id: int,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeRetrieveInventoryItemsResponse:
        """
        Get list of InventoryItem for this showtime.

        InventoryItem is combination of section, price and discount.

        Client need to group all Inventory Items by section_price_discount and order by
        orderNum, ASC, and then by price, DESC.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return await self._get(
            f"/api/v2/shows/{show_id}/showtimes/{showtime_id}/inventoryItems",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ShowtimeRetrieveInventoryItemsResponse,
        )

    async def retrieve_sections(
        self,
        showtime_id: int,
        *,
        id: int,
        chart_key_override: str | NotGiven = NOT_GIVEN,
        include_attributes: bool | NotGiven = NOT_GIVEN,
        max_seats: int | NotGiven = NOT_GIVEN,
        quantity: int | NotGiven = NOT_GIVEN,
        remove_unavailable_seats: bool | NotGiven = NOT_GIVEN,
        sort_by: List[Literal["NAME"]] | NotGiven = NOT_GIVEN,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeRetrieveSectionsResponse:
        """
        Get list of AssignedSection or GASection for this showtime.

        Args:
          chart_key_override: Optional chart key to override the show chart key for this showtime. Should only
              be used in special cases.

          include_attributes: Optional flag to include seat and section attributes

          max_seats: If more than this many seats are available, return this many at a maximum.
              Otherwise, return all available.

          quantity: For showtimes endpoint: Quantity allows filtering showtimes which have
              maxContiguousSeats greater or equal than `quantity`. Only applicable when
              listingType=`REGULAR`

              For showtimes/{showtime_id}/seats: Quantity allows to filter all seatblocks
              which have number of seats greater than or equal to `quantity`.

          remove_unavailable_seats: Optional flag to remove from response the unavailable seats present in redis
              state

          sort_by: List of sorting parameters (strings)

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return await self._get(
            f"/api/v2/shows/{id}/showtimes/{showtime_id}/sections",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "chart_key_override": chart_key_override,
                        "include_attributes": include_attributes,
                        "max_seats": max_seats,
                        "quantity": quantity,
                        "remove_unavailable_seats": remove_unavailable_seats,
                        "sort_by": sort_by,
                    },
                    showtime_retrieve_sections_params.ShowtimeRetrieveSectionsParams,
                ),
            ),
            cast_to=ShowtimeRetrieveSectionsResponse,
        )

    async def retrieve_with_rush_availability(
        self,
        show_id: int,
        *,
        # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
        # The extra values given here take precedence over values defined on the client or passed to this method.
        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
    ) -> ShowtimeRetrieveWithRushAvailabilityResponse:
        """
        Get list of all UPCOMING showtimes for show that have rush tickets available.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        return await self._get(
            f"/api/v2/shows/{show_id}/showtimes/with_rush_availability",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=ShowtimeRetrieveWithRushAvailabilityResponse,
        )


class ShowtimesResourceWithRawResponse:
    def __init__(self, showtimes: ShowtimesResource) -> None:
        self._showtimes = showtimes

        self.list = to_raw_response_wrapper(
            showtimes.list,
        )
        self.retrieve_inventory_items = to_raw_response_wrapper(
            showtimes.retrieve_inventory_items,
        )
        self.retrieve_sections = to_raw_response_wrapper(
            showtimes.retrieve_sections,
        )
        self.retrieve_with_rush_availability = to_raw_response_wrapper(
            showtimes.retrieve_with_rush_availability,
        )


class AsyncShowtimesResourceWithRawResponse:
    def __init__(self, showtimes: AsyncShowtimesResource) -> None:
        self._showtimes = showtimes

        self.list = async_to_raw_response_wrapper(
            showtimes.list,
        )
        self.retrieve_inventory_items = async_to_raw_response_wrapper(
            showtimes.retrieve_inventory_items,
        )
        self.retrieve_sections = async_to_raw_response_wrapper(
            showtimes.retrieve_sections,
        )
        self.retrieve_with_rush_availability = async_to_raw_response_wrapper(
            showtimes.retrieve_with_rush_availability,
        )


class ShowtimesResourceWithStreamingResponse:
    def __init__(self, showtimes: ShowtimesResource) -> None:
        self._showtimes = showtimes

        self.list = to_streamed_response_wrapper(
            showtimes.list,
        )
        self.retrieve_inventory_items = to_streamed_response_wrapper(
            showtimes.retrieve_inventory_items,
        )
        self.retrieve_sections = to_streamed_response_wrapper(
            showtimes.retrieve_sections,
        )
        self.retrieve_with_rush_availability = to_streamed_response_wrapper(
            showtimes.retrieve_with_rush_availability,
        )


class AsyncShowtimesResourceWithStreamingResponse:
    def __init__(self, showtimes: AsyncShowtimesResource) -> None:
        self._showtimes = showtimes

        self.list = async_to_streamed_response_wrapper(
            showtimes.list,
        )
        self.retrieve_inventory_items = async_to_streamed_response_wrapper(
            showtimes.retrieve_inventory_items,
        )
        self.retrieve_sections = async_to_streamed_response_wrapper(
            showtimes.retrieve_sections,
        )
        self.retrieve_with_rush_availability = async_to_streamed_response_wrapper(
            showtimes.retrieve_with_rush_availability,
        )
