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

from __future__ import annotations

from typing import Mapping, cast

import httpx

from .. import _legacy_response
from ..types import content_provenance_check_create_params
from .._files import deepcopy_with_paths
from .._types import Body, Query, Headers, NotGiven, FileTypes, not_given
from .._utils import extract_files, maybe_transform, async_maybe_transform
from .._compat import cached_property
from .._resource import SyncAPIResource, AsyncAPIResource
from .._response import to_streamed_response_wrapper, async_to_streamed_response_wrapper
from .._base_client import make_request_options
from ..types.content_provenance_check import ContentProvenanceCheck

__all__ = ["ContentProvenanceChecks", "AsyncContentProvenanceChecks"]


class ContentProvenanceChecks(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> ContentProvenanceChecksWithRawResponse:
        """
        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/openai/openai-python#accessing-raw-response-data-eg-headers
        """
        return ContentProvenanceChecksWithRawResponse(self)

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

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

    def create(
        self,
        *,
        file: FileTypes,
        # 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,
    ) -> ContentProvenanceCheck:
        """
        Check whether an image or audio file contains known OpenAI provenance signals.
        [Learn more about content provenance](/api/docs/guides/content-provenance).

        If `not_detected`, it means the tool did not find supported signals in the
        uploaded file. The content could still have been generated by OpenAI if the
        metadata was stripped or has evidence of tampering, the watermark was degraded,
        it comes from a legacy generation model, or it was created before provenance
        signals were available. Content could also still be AI-generated by another
        company's model, which the tool currently does not detect.

        Args:
          file: The image or audio file to check for supported OpenAI provenance signals.

          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
        """
        body = deepcopy_with_paths({"file": file}, [["file"]])
        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(
            "/content_provenance_checks",
            body=maybe_transform(body, content_provenance_check_create_params.ContentProvenanceCheckCreateParams),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                security={"bearer_auth": True},
            ),
            cast_to=ContentProvenanceCheck,
        )


class AsyncContentProvenanceChecks(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncContentProvenanceChecksWithRawResponse:
        """
        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/openai/openai-python#accessing-raw-response-data-eg-headers
        """
        return AsyncContentProvenanceChecksWithRawResponse(self)

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

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

    async def create(
        self,
        *,
        file: FileTypes,
        # 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,
    ) -> ContentProvenanceCheck:
        """
        Check whether an image or audio file contains known OpenAI provenance signals.
        [Learn more about content provenance](/api/docs/guides/content-provenance).

        If `not_detected`, it means the tool did not find supported signals in the
        uploaded file. The content could still have been generated by OpenAI if the
        metadata was stripped or has evidence of tampering, the watermark was degraded,
        it comes from a legacy generation model, or it was created before provenance
        signals were available. Content could also still be AI-generated by another
        company's model, which the tool currently does not detect.

        Args:
          file: The image or audio file to check for supported OpenAI provenance signals.

          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
        """
        body = deepcopy_with_paths({"file": file}, [["file"]])
        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(
            "/content_provenance_checks",
            body=await async_maybe_transform(
                body, content_provenance_check_create_params.ContentProvenanceCheckCreateParams
            ),
            files=files,
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                security={"bearer_auth": True},
            ),
            cast_to=ContentProvenanceCheck,
        )


class ContentProvenanceChecksWithRawResponse:
    def __init__(self, content_provenance_checks: ContentProvenanceChecks) -> None:
        self._content_provenance_checks = content_provenance_checks

        self.create = _legacy_response.to_raw_response_wrapper(
            content_provenance_checks.create,
        )


class AsyncContentProvenanceChecksWithRawResponse:
    def __init__(self, content_provenance_checks: AsyncContentProvenanceChecks) -> None:
        self._content_provenance_checks = content_provenance_checks

        self.create = _legacy_response.async_to_raw_response_wrapper(
            content_provenance_checks.create,
        )


class ContentProvenanceChecksWithStreamingResponse:
    def __init__(self, content_provenance_checks: ContentProvenanceChecks) -> None:
        self._content_provenance_checks = content_provenance_checks

        self.create = to_streamed_response_wrapper(
            content_provenance_checks.create,
        )


class AsyncContentProvenanceChecksWithStreamingResponse:
    def __init__(self, content_provenance_checks: AsyncContentProvenanceChecks) -> None:
        self._content_provenance_checks = content_provenance_checks

        self.create = async_to_streamed_response_wrapper(
            content_provenance_checks.create,
        )
