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

from __future__ import annotations

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 import location_retrieve_geosegment_params, location_retrieve_privacy_law_params
from ....types.api.v2.location import Location
from ....types.api.v2.location_list_response import LocationListResponse
from ....types.api.v2.location_retrieve_geolocation_response import LocationRetrieveGeolocationResponse
from ....types.api.v2.location_retrieve_privacy_law_response import LocationRetrievePrivacyLawResponse

__all__ = ["LocationsResource", "AsyncLocationsResource"]


class LocationsResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> LocationsResourceWithRawResponse:
        """
        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 LocationsResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> LocationsResourceWithStreamingResponse:
        """
        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 LocationsResourceWithStreamingResponse(self)

    def retrieve(
        self,
        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,
    ) -> Location:
        """
        Get `Location` with `id`.

        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/locations/{id}",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=Location,
        )

    def list(
        self,
        *,
        # 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,
    ) -> LocationListResponse:
        """Gets all `Locations`."""
        return self._get(
            "/api/v2/locations",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LocationListResponse,
        )

    def retrieve_geolocation(
        self,
        *,
        # 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,
    ) -> LocationRetrieveGeolocationResponse:
        """
        Capture geolocation data from CloudFront headers, and return them as a JSON
        payload.
        """
        return self._get(
            "/api/v2/locations/geolocation",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LocationRetrieveGeolocationResponse,
        )

    def retrieve_geosegment(
        self,
        *,
        location_id: int,
        city: str | NotGiven = NOT_GIVEN,
        country_code: str | NotGiven = NOT_GIVEN,
        country_name: str | NotGiven = NOT_GIVEN,
        postal_code: str | NotGiven = NOT_GIVEN,
        region_code: str | NotGiven = NOT_GIVEN,
        region_name: str | 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,
    ) -> str:
        """
        Given a set of params, determine the geosegment a customer belongs to, relative
        to the main browsing location. Return values can be LOCAL, REGIONAL or TOURIST.

        Args:
          location_id: Id of the viewing location.

          city: City name, as we get it from AWS CloudFront's headers.

          country_code: Country code, as we get it from AWS CloudFront's headers.

          country_name: Country name, as we get it from AWS CloudFront's headers.

          postal_code: Postal code, as we get it from AWS CloudFront's headers.

          region_code: Region code, as we get it from AWS CloudFront's headers.

          region_name: Region name, as we get it from AWS CloudFront's headers.

          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(
            "/api/v2/locations/geosegment",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "location_id": location_id,
                        "city": city,
                        "country_code": country_code,
                        "country_name": country_name,
                        "postal_code": postal_code,
                        "region_code": region_code,
                        "region_name": region_name,
                    },
                    location_retrieve_geosegment_params.LocationRetrieveGeosegmentParams,
                ),
            ),
            cast_to=str,
        )

    def retrieve_privacy_law(
        self,
        *,
        country_abbr: str | NotGiven = NOT_GIVEN,
        location: int | 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,
    ) -> LocationRetrievePrivacyLawResponse:
        """
        Given a set of params, determine the privacy law by which the anticipated
        customer would be covered, assuming they complete the sign-up process.

        Args:
          country_abbr: The 2-letter country code based on the locale that the client determines. Part
              of the standard ISO 3166 format (i.e., US for en_US).

          location: location Id

          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(
            "/api/v2/locations/privacyLaw",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform(
                    {
                        "country_abbr": country_abbr,
                        "location": location,
                    },
                    location_retrieve_privacy_law_params.LocationRetrievePrivacyLawParams,
                ),
            ),
            cast_to=LocationRetrievePrivacyLawResponse,
        )


class AsyncLocationsResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncLocationsResourceWithRawResponse:
        """
        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 AsyncLocationsResourceWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncLocationsResourceWithStreamingResponse:
        """
        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 AsyncLocationsResourceWithStreamingResponse(self)

    async def retrieve(
        self,
        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,
    ) -> Location:
        """
        Get `Location` with `id`.

        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/locations/{id}",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=Location,
        )

    async def list(
        self,
        *,
        # 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,
    ) -> LocationListResponse:
        """Gets all `Locations`."""
        return await self._get(
            "/api/v2/locations",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LocationListResponse,
        )

    async def retrieve_geolocation(
        self,
        *,
        # 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,
    ) -> LocationRetrieveGeolocationResponse:
        """
        Capture geolocation data from CloudFront headers, and return them as a JSON
        payload.
        """
        return await self._get(
            "/api/v2/locations/geolocation",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=LocationRetrieveGeolocationResponse,
        )

    async def retrieve_geosegment(
        self,
        *,
        location_id: int,
        city: str | NotGiven = NOT_GIVEN,
        country_code: str | NotGiven = NOT_GIVEN,
        country_name: str | NotGiven = NOT_GIVEN,
        postal_code: str | NotGiven = NOT_GIVEN,
        region_code: str | NotGiven = NOT_GIVEN,
        region_name: str | 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,
    ) -> str:
        """
        Given a set of params, determine the geosegment a customer belongs to, relative
        to the main browsing location. Return values can be LOCAL, REGIONAL or TOURIST.

        Args:
          location_id: Id of the viewing location.

          city: City name, as we get it from AWS CloudFront's headers.

          country_code: Country code, as we get it from AWS CloudFront's headers.

          country_name: Country name, as we get it from AWS CloudFront's headers.

          postal_code: Postal code, as we get it from AWS CloudFront's headers.

          region_code: Region code, as we get it from AWS CloudFront's headers.

          region_name: Region name, as we get it from AWS CloudFront's headers.

          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(
            "/api/v2/locations/geosegment",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "location_id": location_id,
                        "city": city,
                        "country_code": country_code,
                        "country_name": country_name,
                        "postal_code": postal_code,
                        "region_code": region_code,
                        "region_name": region_name,
                    },
                    location_retrieve_geosegment_params.LocationRetrieveGeosegmentParams,
                ),
            ),
            cast_to=str,
        )

    async def retrieve_privacy_law(
        self,
        *,
        country_abbr: str | NotGiven = NOT_GIVEN,
        location: int | 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,
    ) -> LocationRetrievePrivacyLawResponse:
        """
        Given a set of params, determine the privacy law by which the anticipated
        customer would be covered, assuming they complete the sign-up process.

        Args:
          country_abbr: The 2-letter country code based on the locale that the client determines. Part
              of the standard ISO 3166 format (i.e., US for en_US).

          location: location Id

          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(
            "/api/v2/locations/privacyLaw",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {
                        "country_abbr": country_abbr,
                        "location": location,
                    },
                    location_retrieve_privacy_law_params.LocationRetrievePrivacyLawParams,
                ),
            ),
            cast_to=LocationRetrievePrivacyLawResponse,
        )


class LocationsResourceWithRawResponse:
    def __init__(self, locations: LocationsResource) -> None:
        self._locations = locations

        self.retrieve = to_raw_response_wrapper(
            locations.retrieve,
        )
        self.list = to_raw_response_wrapper(
            locations.list,
        )
        self.retrieve_geolocation = to_raw_response_wrapper(
            locations.retrieve_geolocation,
        )
        self.retrieve_geosegment = to_raw_response_wrapper(
            locations.retrieve_geosegment,
        )
        self.retrieve_privacy_law = to_raw_response_wrapper(
            locations.retrieve_privacy_law,
        )


class AsyncLocationsResourceWithRawResponse:
    def __init__(self, locations: AsyncLocationsResource) -> None:
        self._locations = locations

        self.retrieve = async_to_raw_response_wrapper(
            locations.retrieve,
        )
        self.list = async_to_raw_response_wrapper(
            locations.list,
        )
        self.retrieve_geolocation = async_to_raw_response_wrapper(
            locations.retrieve_geolocation,
        )
        self.retrieve_geosegment = async_to_raw_response_wrapper(
            locations.retrieve_geosegment,
        )
        self.retrieve_privacy_law = async_to_raw_response_wrapper(
            locations.retrieve_privacy_law,
        )


class LocationsResourceWithStreamingResponse:
    def __init__(self, locations: LocationsResource) -> None:
        self._locations = locations

        self.retrieve = to_streamed_response_wrapper(
            locations.retrieve,
        )
        self.list = to_streamed_response_wrapper(
            locations.list,
        )
        self.retrieve_geolocation = to_streamed_response_wrapper(
            locations.retrieve_geolocation,
        )
        self.retrieve_geosegment = to_streamed_response_wrapper(
            locations.retrieve_geosegment,
        )
        self.retrieve_privacy_law = to_streamed_response_wrapper(
            locations.retrieve_privacy_law,
        )


class AsyncLocationsResourceWithStreamingResponse:
    def __init__(self, locations: AsyncLocationsResource) -> None:
        self._locations = locations

        self.retrieve = async_to_streamed_response_wrapper(
            locations.retrieve,
        )
        self.list = async_to_streamed_response_wrapper(
            locations.list,
        )
        self.retrieve_geolocation = async_to_streamed_response_wrapper(
            locations.retrieve_geolocation,
        )
        self.retrieve_geosegment = async_to_streamed_response_wrapper(
            locations.retrieve_geosegment,
        )
        self.retrieve_privacy_law = async_to_streamed_response_wrapper(
            locations.retrieve_privacy_law,
        )
