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

from __future__ import annotations

from typing import Any, Type, cast
from typing_extensions import Literal

import httpx

from ..types import DNSSECDNSSEC, DNSSECDeleteResponse, dnssec_edit_params
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 .._wrappers import ResultWrapper
from .._base_client import (
    make_request_options,
)

__all__ = ["DNSSEC", "AsyncDNSSEC"]


class DNSSEC(SyncAPIResource):
    @cached_property
    def with_raw_response(self) -> DNSSECWithRawResponse:
        return DNSSECWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> DNSSECWithStreamingResponse:
        return DNSSECWithStreamingResponse(self)

    def delete(
        self,
        *,
        zone_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,
    ) -> DNSSECDeleteResponse:
        """
        Delete DNSSEC.

        Args:
          zone_id: Identifier

          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 zone_id:
            raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
        return cast(
            DNSSECDeleteResponse,
            self._delete(
                f"/zones/{zone_id}/dnssec",
                options=make_request_options(
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    timeout=timeout,
                    post_parser=ResultWrapper._unwrapper,
                ),
                cast_to=cast(
                    Any, ResultWrapper[DNSSECDeleteResponse]
                ),  # Union types cannot be passed in as arguments in the type system
            ),
        )

    def edit(
        self,
        *,
        zone_id: str,
        dnssec_multi_signer: bool | NotGiven = NOT_GIVEN,
        dnssec_presigned: bool | NotGiven = NOT_GIVEN,
        status: Literal["active", "disabled"] | 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,
    ) -> DNSSECDNSSEC:
        """
        Enable or disable DNSSEC.

        Args:
          zone_id: Identifier

          dnssec_multi_signer: If true, multi-signer DNSSEC is enabled on the zone, allowing multiple providers
              to serve a DNSSEC-signed zone at the same time. This is required for DNSKEY
              records (except those automatically generated by Cloudflare) to be added to the
              zone.

              See
              [Multi-signer DNSSEC](https://developers.cloudflare.com/dns/dnssec/multi-signer-dnssec/)
              for details.

          dnssec_presigned: If true, allows Cloudflare to transfer in a DNSSEC-signed zone including
              signatures from an external provider, without requiring Cloudflare to sign any
              records on the fly.

              Note that this feature has some limitations. See
              [Cloudflare as Secondary](https://developers.cloudflare.com/dns/zone-setups/zone-transfers/cloudflare-as-secondary/setup/#dnssec)
              for details.

          status: Status of DNSSEC, based on user-desired state and presence of necessary records.

          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 zone_id:
            raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
        return self._patch(
            f"/zones/{zone_id}/dnssec",
            body=maybe_transform(
                {
                    "dnssec_multi_signer": dnssec_multi_signer,
                    "dnssec_presigned": dnssec_presigned,
                    "status": status,
                },
                dnssec_edit_params.DNSSECEditParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                post_parser=ResultWrapper._unwrapper,
            ),
            cast_to=cast(Type[DNSSECDNSSEC], ResultWrapper[DNSSECDNSSEC]),
        )

    def get(
        self,
        *,
        zone_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,
    ) -> DNSSECDNSSEC:
        """
        Details about DNSSEC status and configuration.

        Args:
          zone_id: Identifier

          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 zone_id:
            raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
        return self._get(
            f"/zones/{zone_id}/dnssec",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                post_parser=ResultWrapper._unwrapper,
            ),
            cast_to=cast(Type[DNSSECDNSSEC], ResultWrapper[DNSSECDNSSEC]),
        )


class AsyncDNSSEC(AsyncAPIResource):
    @cached_property
    def with_raw_response(self) -> AsyncDNSSECWithRawResponse:
        return AsyncDNSSECWithRawResponse(self)

    @cached_property
    def with_streaming_response(self) -> AsyncDNSSECWithStreamingResponse:
        return AsyncDNSSECWithStreamingResponse(self)

    async def delete(
        self,
        *,
        zone_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,
    ) -> DNSSECDeleteResponse:
        """
        Delete DNSSEC.

        Args:
          zone_id: Identifier

          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 zone_id:
            raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
        return cast(
            DNSSECDeleteResponse,
            await self._delete(
                f"/zones/{zone_id}/dnssec",
                options=make_request_options(
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    timeout=timeout,
                    post_parser=ResultWrapper._unwrapper,
                ),
                cast_to=cast(
                    Any, ResultWrapper[DNSSECDeleteResponse]
                ),  # Union types cannot be passed in as arguments in the type system
            ),
        )

    async def edit(
        self,
        *,
        zone_id: str,
        dnssec_multi_signer: bool | NotGiven = NOT_GIVEN,
        dnssec_presigned: bool | NotGiven = NOT_GIVEN,
        status: Literal["active", "disabled"] | 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,
    ) -> DNSSECDNSSEC:
        """
        Enable or disable DNSSEC.

        Args:
          zone_id: Identifier

          dnssec_multi_signer: If true, multi-signer DNSSEC is enabled on the zone, allowing multiple providers
              to serve a DNSSEC-signed zone at the same time. This is required for DNSKEY
              records (except those automatically generated by Cloudflare) to be added to the
              zone.

              See
              [Multi-signer DNSSEC](https://developers.cloudflare.com/dns/dnssec/multi-signer-dnssec/)
              for details.

          dnssec_presigned: If true, allows Cloudflare to transfer in a DNSSEC-signed zone including
              signatures from an external provider, without requiring Cloudflare to sign any
              records on the fly.

              Note that this feature has some limitations. See
              [Cloudflare as Secondary](https://developers.cloudflare.com/dns/zone-setups/zone-transfers/cloudflare-as-secondary/setup/#dnssec)
              for details.

          status: Status of DNSSEC, based on user-desired state and presence of necessary records.

          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 zone_id:
            raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
        return await self._patch(
            f"/zones/{zone_id}/dnssec",
            body=await async_maybe_transform(
                {
                    "dnssec_multi_signer": dnssec_multi_signer,
                    "dnssec_presigned": dnssec_presigned,
                    "status": status,
                },
                dnssec_edit_params.DNSSECEditParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                post_parser=ResultWrapper._unwrapper,
            ),
            cast_to=cast(Type[DNSSECDNSSEC], ResultWrapper[DNSSECDNSSEC]),
        )

    async def get(
        self,
        *,
        zone_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,
    ) -> DNSSECDNSSEC:
        """
        Details about DNSSEC status and configuration.

        Args:
          zone_id: Identifier

          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 zone_id:
            raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}")
        return await self._get(
            f"/zones/{zone_id}/dnssec",
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                post_parser=ResultWrapper._unwrapper,
            ),
            cast_to=cast(Type[DNSSECDNSSEC], ResultWrapper[DNSSECDNSSEC]),
        )


class DNSSECWithRawResponse:
    def __init__(self, dnssec: DNSSEC) -> None:
        self._dnssec = dnssec

        self.delete = to_raw_response_wrapper(
            dnssec.delete,
        )
        self.edit = to_raw_response_wrapper(
            dnssec.edit,
        )
        self.get = to_raw_response_wrapper(
            dnssec.get,
        )


class AsyncDNSSECWithRawResponse:
    def __init__(self, dnssec: AsyncDNSSEC) -> None:
        self._dnssec = dnssec

        self.delete = async_to_raw_response_wrapper(
            dnssec.delete,
        )
        self.edit = async_to_raw_response_wrapper(
            dnssec.edit,
        )
        self.get = async_to_raw_response_wrapper(
            dnssec.get,
        )


class DNSSECWithStreamingResponse:
    def __init__(self, dnssec: DNSSEC) -> None:
        self._dnssec = dnssec

        self.delete = to_streamed_response_wrapper(
            dnssec.delete,
        )
        self.edit = to_streamed_response_wrapper(
            dnssec.edit,
        )
        self.get = to_streamed_response_wrapper(
            dnssec.get,
        )


class AsyncDNSSECWithStreamingResponse:
    def __init__(self, dnssec: AsyncDNSSEC) -> None:
        self._dnssec = dnssec

        self.delete = async_to_streamed_response_wrapper(
            dnssec.delete,
        )
        self.edit = async_to_streamed_response_wrapper(
            dnssec.edit,
        )
        self.get = async_to_streamed_response_wrapper(
            dnssec.get,
        )
