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

from __future__ import annotations

from typing import Mapping, Optional, cast

import httpx

from ..types import index_url_params, index_face_params, index_upload_params
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
from .._utils import (
    extract_files,
    maybe_transform,
    strip_not_given,
    deepcopy_minimal,
    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

__all__ = ["IndexResource", "AsyncIndexResource"]


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

        For more information, see https://www.github.com/mixpeek/python-client#accessing-raw-response-data-eg-headers
        """
        return IndexResourceWithRawResponse(self)

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

        For more information, see https://www.github.com/mixpeek/python-client#with_streaming_response
        """
        return IndexResourceWithStreamingResponse(self)

    def face(
        self,
        *,
        collection_id: str,
        file: FileTypes,
        metadata: str | NotGiven = NOT_GIVEN,
        authorization: str | NotGiven = NOT_GIVEN,
        index_id: 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,
    ) -> object:
        """
        Index Face

        Args:
          index_id: filter by organization

          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
        """
        extra_headers = {
            **strip_not_given(
                {
                    "Authorization": authorization,
                    "index-id": index_id,
                }
            ),
            **(extra_headers or {}),
        }
        body = deepcopy_minimal(
            {
                "collection_id": collection_id,
                "file": file,
                "metadata": metadata,
            }
        )
        files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
        # It should be noted that the actual Content-Type header that will be
        # sent to the server will contain a `boundary` parameter, e.g.
        # multipart/form-data; boundary=---abc--
        extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
        return self._post(
            "/index/face",
            body=maybe_transform(body, index_face_params.IndexFaceParams),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=object,
        )

    def upload(
        self,
        *,
        collection_id: str,
        file: FileTypes,
        image_settings: str | NotGiven = NOT_GIVEN,
        metadata: str | NotGiven = NOT_GIVEN,
        video_settings: str | NotGiven = NOT_GIVEN,
        authorization: str | NotGiven = NOT_GIVEN,
        index_id: 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,
    ) -> object:
        """
        Index Upload

        Args:
          index_id: filter by organization

          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
        """
        extra_headers = {
            **strip_not_given(
                {
                    "Authorization": authorization,
                    "index-id": index_id,
                }
            ),
            **(extra_headers or {}),
        }
        body = deepcopy_minimal(
            {
                "collection_id": collection_id,
                "file": file,
                "image_settings": image_settings,
                "metadata": metadata,
                "video_settings": video_settings,
            }
        )
        files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
        # It should be noted that the actual Content-Type header that will be
        # sent to the server will contain a `boundary` parameter, e.g.
        # multipart/form-data; boundary=---abc--
        extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
        return self._post(
            "/index/upload",
            body=maybe_transform(body, index_upload_params.IndexUploadParams),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=object,
        )

    def url(
        self,
        *,
        collection_id: str,
        url: str,
        image_settings: Optional[index_url_params.ImageSettings] | NotGiven = NOT_GIVEN,
        metadata: object | NotGiven = NOT_GIVEN,
        should_save: Optional[bool] | NotGiven = NOT_GIVEN,
        video_settings: Optional[index_url_params.VideoSettings] | NotGiven = NOT_GIVEN,
        authorization: str | NotGiven = NOT_GIVEN,
        index_id: 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,
    ) -> object:
        """
        Index Url

        Args:
          metadata: Additional metadata associated with the file

          should_save: Whether to upload the processed file to S3

          index_id: filter by organization

          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
        """
        extra_headers = {
            **strip_not_given(
                {
                    "Authorization": authorization,
                    "index-id": index_id,
                }
            ),
            **(extra_headers or {}),
        }
        return self._post(
            "/index/url",
            body=maybe_transform(
                {
                    "collection_id": collection_id,
                    "url": url,
                    "image_settings": image_settings,
                    "metadata": metadata,
                    "should_save": should_save,
                    "video_settings": video_settings,
                },
                index_url_params.IndexURLParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=object,
        )


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

        For more information, see https://www.github.com/mixpeek/python-client#accessing-raw-response-data-eg-headers
        """
        return AsyncIndexResourceWithRawResponse(self)

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

        For more information, see https://www.github.com/mixpeek/python-client#with_streaming_response
        """
        return AsyncIndexResourceWithStreamingResponse(self)

    async def face(
        self,
        *,
        collection_id: str,
        file: FileTypes,
        metadata: str | NotGiven = NOT_GIVEN,
        authorization: str | NotGiven = NOT_GIVEN,
        index_id: 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,
    ) -> object:
        """
        Index Face

        Args:
          index_id: filter by organization

          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
        """
        extra_headers = {
            **strip_not_given(
                {
                    "Authorization": authorization,
                    "index-id": index_id,
                }
            ),
            **(extra_headers or {}),
        }
        body = deepcopy_minimal(
            {
                "collection_id": collection_id,
                "file": file,
                "metadata": metadata,
            }
        )
        files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
        # It should be noted that the actual Content-Type header that will be
        # sent to the server will contain a `boundary` parameter, e.g.
        # multipart/form-data; boundary=---abc--
        extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
        return await self._post(
            "/index/face",
            body=await async_maybe_transform(body, index_face_params.IndexFaceParams),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=object,
        )

    async def upload(
        self,
        *,
        collection_id: str,
        file: FileTypes,
        image_settings: str | NotGiven = NOT_GIVEN,
        metadata: str | NotGiven = NOT_GIVEN,
        video_settings: str | NotGiven = NOT_GIVEN,
        authorization: str | NotGiven = NOT_GIVEN,
        index_id: 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,
    ) -> object:
        """
        Index Upload

        Args:
          index_id: filter by organization

          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
        """
        extra_headers = {
            **strip_not_given(
                {
                    "Authorization": authorization,
                    "index-id": index_id,
                }
            ),
            **(extra_headers or {}),
        }
        body = deepcopy_minimal(
            {
                "collection_id": collection_id,
                "file": file,
                "image_settings": image_settings,
                "metadata": metadata,
                "video_settings": video_settings,
            }
        )
        files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
        # It should be noted that the actual Content-Type header that will be
        # sent to the server will contain a `boundary` parameter, e.g.
        # multipart/form-data; boundary=---abc--
        extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
        return await self._post(
            "/index/upload",
            body=await async_maybe_transform(body, index_upload_params.IndexUploadParams),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=object,
        )

    async def url(
        self,
        *,
        collection_id: str,
        url: str,
        image_settings: Optional[index_url_params.ImageSettings] | NotGiven = NOT_GIVEN,
        metadata: object | NotGiven = NOT_GIVEN,
        should_save: Optional[bool] | NotGiven = NOT_GIVEN,
        video_settings: Optional[index_url_params.VideoSettings] | NotGiven = NOT_GIVEN,
        authorization: str | NotGiven = NOT_GIVEN,
        index_id: 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,
    ) -> object:
        """
        Index Url

        Args:
          metadata: Additional metadata associated with the file

          should_save: Whether to upload the processed file to S3

          index_id: filter by organization

          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
        """
        extra_headers = {
            **strip_not_given(
                {
                    "Authorization": authorization,
                    "index-id": index_id,
                }
            ),
            **(extra_headers or {}),
        }
        return await self._post(
            "/index/url",
            body=await async_maybe_transform(
                {
                    "collection_id": collection_id,
                    "url": url,
                    "image_settings": image_settings,
                    "metadata": metadata,
                    "should_save": should_save,
                    "video_settings": video_settings,
                },
                index_url_params.IndexURLParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=object,
        )


class IndexResourceWithRawResponse:
    def __init__(self, index: IndexResource) -> None:
        self._index = index

        self.face = to_raw_response_wrapper(
            index.face,
        )
        self.upload = to_raw_response_wrapper(
            index.upload,
        )
        self.url = to_raw_response_wrapper(
            index.url,
        )


class AsyncIndexResourceWithRawResponse:
    def __init__(self, index: AsyncIndexResource) -> None:
        self._index = index

        self.face = async_to_raw_response_wrapper(
            index.face,
        )
        self.upload = async_to_raw_response_wrapper(
            index.upload,
        )
        self.url = async_to_raw_response_wrapper(
            index.url,
        )


class IndexResourceWithStreamingResponse:
    def __init__(self, index: IndexResource) -> None:
        self._index = index

        self.face = to_streamed_response_wrapper(
            index.face,
        )
        self.upload = to_streamed_response_wrapper(
            index.upload,
        )
        self.url = to_streamed_response_wrapper(
            index.url,
        )


class AsyncIndexResourceWithStreamingResponse:
    def __init__(self, index: AsyncIndexResource) -> None:
        self._index = index

        self.face = async_to_streamed_response_wrapper(
            index.face,
        )
        self.upload = async_to_streamed_response_wrapper(
            index.upload,
        )
        self.url = async_to_streamed_response_wrapper(
            index.url,
        )
