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

from __future__ import annotations

import httpx

from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given
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.dataframer import red_team_spec_create_params, red_team_spec_update_params
from ...types.dataframer.red_team_spec_list_response import RedTeamSpecListResponse
from ...types.dataframer.red_team_spec_create_response import RedTeamSpecCreateResponse
from ...types.dataframer.red_team_spec_update_response import RedTeamSpecUpdateResponse
from ...types.dataframer.red_team_spec_retrieve_response import RedTeamSpecRetrieveResponse

__all__ = ["RedTeamSpecsResource", "AsyncRedTeamSpecsResource"]


class RedTeamSpecsResource(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> RedTeamSpecsResourceWithRawResponse:
        """
        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/aimonlabs/dataframer-python-sdk#accessing-raw-response-data-eg-headers
        """
        return RedTeamSpecsResourceWithRawResponse(self)

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

        For more information, see https://www.github.com/aimonlabs/dataframer-python-sdk#with_streaming_response
        """
        return RedTeamSpecsResourceWithStreamingResponse(self)

    def create(
        self,
        *,
        app_description: str,
        domain_description: str,
        name: str,
        concerns: str | Omit = omit,
        # 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,
    ) -> RedTeamSpecCreateResponse:
        """
        Create a new red team specification.

        ## What is Red Teaming?

        Red teaming generates adversarial prompts designed to test your LLM
        application's safety guardrails. Given a description of your application and its
        domain, it identifies potential undesirable behaviors and creates prompts that
        attempt to trigger them.

        **Workflow:**

        1. Create a red team spec (this endpoint) describing your application
        2. Create a run to generate adversarial prompts
        3. Poll the status until complete
        4. Get the results containing behaviors and adversarial prompts

        **When to use the main Specs/Runs workflow instead:** Red teaming is designed
        for generating relatively short adversarial prompts and produces fewer than 100
        prompts per run. If you need large volumes of diverse, complex synthetic data,
        use the main Specs and Runs workflow instead.

        Spec names are automatically converted to snake_case and must be unique within
        your company.

        Args:
          app_description: Description of the application being tested, including its purpose and key
              functionality

          domain_description: Description of the domain or industry the application operates in (e.g.,
              'Healthcare', 'E-commerce', 'Financial services')

          name: Name for the spec (will be converted to snake_case, must be unique within
              company)

          concerns: Optional specific security concerns or undesirable behaviors to focus on (e.g.,
              'Should not provide medical diagnoses')

          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._post(
            "/api/dataframer/red-team-specs/",
            body=maybe_transform(
                {
                    "app_description": app_description,
                    "domain_description": domain_description,
                    "name": name,
                    "concerns": concerns,
                },
                red_team_spec_create_params.RedTeamSpecCreateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecCreateResponse,
        )

    def retrieve(
        self,
        spec_id: str,
        *,
        # 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,
    ) -> RedTeamSpecRetrieveResponse:
        """
        Get a specific red team spec

        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
        """
        if not spec_id:
            raise ValueError(f"Expected a non-empty value for `spec_id` but received {spec_id!r}")
        return self._get(
            f"/api/dataframer/red-team-specs/{spec_id}/",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecRetrieveResponse,
        )

    def update(
        self,
        spec_id: str,
        *,
        app_description: str | Omit = omit,
        concerns: str | Omit = omit,
        domain_description: str | Omit = omit,
        name: str | Omit = omit,
        # 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,
    ) -> RedTeamSpecUpdateResponse:
        """
        Update a red team spec

        Args:
          app_description: Updated application description

          concerns: Updated security concerns

          domain_description: Updated domain description

          name: New name for the spec (will be converted to snake_case)

          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
        """
        if not spec_id:
            raise ValueError(f"Expected a non-empty value for `spec_id` but received {spec_id!r}")
        return self._patch(
            f"/api/dataframer/red-team-specs/{spec_id}/",
            body=maybe_transform(
                {
                    "app_description": app_description,
                    "concerns": concerns,
                    "domain_description": domain_description,
                    "name": name,
                },
                red_team_spec_update_params.RedTeamSpecUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecUpdateResponse,
        )

    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,
    ) -> RedTeamSpecListResponse:
        """Get all red team specs"""
        return self._get(
            "/api/dataframer/red-team-specs/",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecListResponse,
        )

    def delete(
        self,
        spec_id: str,
        *,
        # 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,
    ) -> None:
        """
        Delete a red team spec

        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
        """
        if not spec_id:
            raise ValueError(f"Expected a non-empty value for `spec_id` but received {spec_id!r}")
        extra_headers = {"Accept": "*/*", **(extra_headers or {})}
        return self._delete(
            f"/api/dataframer/red-team-specs/{spec_id}/",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=NoneType,
        )


class AsyncRedTeamSpecsResource(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncRedTeamSpecsResourceWithRawResponse:
        """
        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/aimonlabs/dataframer-python-sdk#accessing-raw-response-data-eg-headers
        """
        return AsyncRedTeamSpecsResourceWithRawResponse(self)

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

        For more information, see https://www.github.com/aimonlabs/dataframer-python-sdk#with_streaming_response
        """
        return AsyncRedTeamSpecsResourceWithStreamingResponse(self)

    async def create(
        self,
        *,
        app_description: str,
        domain_description: str,
        name: str,
        concerns: str | Omit = omit,
        # 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,
    ) -> RedTeamSpecCreateResponse:
        """
        Create a new red team specification.

        ## What is Red Teaming?

        Red teaming generates adversarial prompts designed to test your LLM
        application's safety guardrails. Given a description of your application and its
        domain, it identifies potential undesirable behaviors and creates prompts that
        attempt to trigger them.

        **Workflow:**

        1. Create a red team spec (this endpoint) describing your application
        2. Create a run to generate adversarial prompts
        3. Poll the status until complete
        4. Get the results containing behaviors and adversarial prompts

        **When to use the main Specs/Runs workflow instead:** Red teaming is designed
        for generating relatively short adversarial prompts and produces fewer than 100
        prompts per run. If you need large volumes of diverse, complex synthetic data,
        use the main Specs and Runs workflow instead.

        Spec names are automatically converted to snake_case and must be unique within
        your company.

        Args:
          app_description: Description of the application being tested, including its purpose and key
              functionality

          domain_description: Description of the domain or industry the application operates in (e.g.,
              'Healthcare', 'E-commerce', 'Financial services')

          name: Name for the spec (will be converted to snake_case, must be unique within
              company)

          concerns: Optional specific security concerns or undesirable behaviors to focus on (e.g.,
              'Should not provide medical diagnoses')

          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._post(
            "/api/dataframer/red-team-specs/",
            body=await async_maybe_transform(
                {
                    "app_description": app_description,
                    "domain_description": domain_description,
                    "name": name,
                    "concerns": concerns,
                },
                red_team_spec_create_params.RedTeamSpecCreateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecCreateResponse,
        )

    async def retrieve(
        self,
        spec_id: str,
        *,
        # 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,
    ) -> RedTeamSpecRetrieveResponse:
        """
        Get a specific red team spec

        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
        """
        if not spec_id:
            raise ValueError(f"Expected a non-empty value for `spec_id` but received {spec_id!r}")
        return await self._get(
            f"/api/dataframer/red-team-specs/{spec_id}/",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecRetrieveResponse,
        )

    async def update(
        self,
        spec_id: str,
        *,
        app_description: str | Omit = omit,
        concerns: str | Omit = omit,
        domain_description: str | Omit = omit,
        name: str | Omit = omit,
        # 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,
    ) -> RedTeamSpecUpdateResponse:
        """
        Update a red team spec

        Args:
          app_description: Updated application description

          concerns: Updated security concerns

          domain_description: Updated domain description

          name: New name for the spec (will be converted to snake_case)

          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
        """
        if not spec_id:
            raise ValueError(f"Expected a non-empty value for `spec_id` but received {spec_id!r}")
        return await self._patch(
            f"/api/dataframer/red-team-specs/{spec_id}/",
            body=await async_maybe_transform(
                {
                    "app_description": app_description,
                    "concerns": concerns,
                    "domain_description": domain_description,
                    "name": name,
                },
                red_team_spec_update_params.RedTeamSpecUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecUpdateResponse,
        )

    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,
    ) -> RedTeamSpecListResponse:
        """Get all red team specs"""
        return await self._get(
            "/api/dataframer/red-team-specs/",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=RedTeamSpecListResponse,
        )

    async def delete(
        self,
        spec_id: str,
        *,
        # 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,
    ) -> None:
        """
        Delete a red team spec

        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
        """
        if not spec_id:
            raise ValueError(f"Expected a non-empty value for `spec_id` but received {spec_id!r}")
        extra_headers = {"Accept": "*/*", **(extra_headers or {})}
        return await self._delete(
            f"/api/dataframer/red-team-specs/{spec_id}/",
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            cast_to=NoneType,
        )


class RedTeamSpecsResourceWithRawResponse:
    def __init__(self, red_team_specs: RedTeamSpecsResource) -> None:
        self._red_team_specs = red_team_specs

        self.create = to_raw_response_wrapper(
            red_team_specs.create,
        )
        self.retrieve = to_raw_response_wrapper(
            red_team_specs.retrieve,
        )
        self.update = to_raw_response_wrapper(
            red_team_specs.update,
        )
        self.list = to_raw_response_wrapper(
            red_team_specs.list,
        )
        self.delete = to_raw_response_wrapper(
            red_team_specs.delete,
        )


class AsyncRedTeamSpecsResourceWithRawResponse:
    def __init__(self, red_team_specs: AsyncRedTeamSpecsResource) -> None:
        self._red_team_specs = red_team_specs

        self.create = async_to_raw_response_wrapper(
            red_team_specs.create,
        )
        self.retrieve = async_to_raw_response_wrapper(
            red_team_specs.retrieve,
        )
        self.update = async_to_raw_response_wrapper(
            red_team_specs.update,
        )
        self.list = async_to_raw_response_wrapper(
            red_team_specs.list,
        )
        self.delete = async_to_raw_response_wrapper(
            red_team_specs.delete,
        )


class RedTeamSpecsResourceWithStreamingResponse:
    def __init__(self, red_team_specs: RedTeamSpecsResource) -> None:
        self._red_team_specs = red_team_specs

        self.create = to_streamed_response_wrapper(
            red_team_specs.create,
        )
        self.retrieve = to_streamed_response_wrapper(
            red_team_specs.retrieve,
        )
        self.update = to_streamed_response_wrapper(
            red_team_specs.update,
        )
        self.list = to_streamed_response_wrapper(
            red_team_specs.list,
        )
        self.delete = to_streamed_response_wrapper(
            red_team_specs.delete,
        )


class AsyncRedTeamSpecsResourceWithStreamingResponse:
    def __init__(self, red_team_specs: AsyncRedTeamSpecsResource) -> None:
        self._red_team_specs = red_team_specs

        self.create = async_to_streamed_response_wrapper(
            red_team_specs.create,
        )
        self.retrieve = async_to_streamed_response_wrapper(
            red_team_specs.retrieve,
        )
        self.update = async_to_streamed_response_wrapper(
            red_team_specs.update,
        )
        self.list = async_to_streamed_response_wrapper(
            red_team_specs.list,
        )
        self.delete = async_to_streamed_response_wrapper(
            red_team_specs.delete,
        )
