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

from __future__ import annotations

from typing import Any, Dict, List, Type, Optional, cast
from typing_extensions import Literal, overload

import httpx

from ...._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
from ...._utils import path_template, required_args, 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 ....pagination import SyncSinglePage, AsyncSinglePage
from ...._base_client import AsyncPaginator, make_request_options
from ....types.workers.scripts import (
    secret_get_params,
    secret_delete_params,
    secret_update_params,
    secret_bulk_update_params,
)
from ....types.workers.scripts.secret_get_response import SecretGetResponse
from ....types.workers.scripts.secret_list_response import SecretListResponse
from ....types.workers.scripts.secret_update_response import SecretUpdateResponse
from ....types.workers.scripts.secret_bulk_update_response import SecretBulkUpdateResponse

__all__ = ["SecretsResource", "AsyncSecretsResource"]


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

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

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

    @overload
    def update(
        self,
        script_name: str,
        *,
        account_id: str,
        name: str,
        text: str,
        type: Literal["secret_text"],
        # 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,
    ) -> Optional[SecretUpdateResponse]:
        """
        Add a secret to a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          name: A JavaScript variable name for the binding.

          text: The secret value to use.

          type: The kind of resource that the binding provides.

          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
        """
        ...

    @overload
    def update(
        self,
        script_name: str,
        *,
        account_id: str,
        algorithm: object,
        format: Literal["raw", "pkcs8", "spki", "jwk"],
        name: str,
        type: Literal["secret_key"],
        usages: List[
            Literal["encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey"]
        ],
        key_base64: str | Omit = omit,
        key_jwk: object | 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,
    ) -> Optional[SecretUpdateResponse]:
        """
        Add a secret to a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          algorithm: Algorithm-specific key parameters.
              [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#algorithm).

          format: Data format of the key.
              [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#format).

          name: A JavaScript variable name for the binding.

          type: The kind of resource that the binding provides.

          usages: Allowed operations with the key.
              [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#keyUsages).

          key_base64: Base64-encoded key data. Required if `format` is "raw", "pkcs8", or "spki".

          key_jwk: Key data in
              [JSON Web Key](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#json_web_key)
              format. Required if `format` is "jwk".

          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
        """
        ...

    @required_args(
        ["account_id", "name", "text", "type"], ["account_id", "algorithm", "format", "name", "type", "usages"]
    )
    def update(
        self,
        script_name: str,
        *,
        account_id: str,
        name: str,
        text: str | Omit = omit,
        type: Literal["secret_text"] | Literal["secret_key"],
        algorithm: object | Omit = omit,
        format: Literal["raw", "pkcs8", "spki", "jwk"] | Omit = omit,
        usages: List[Literal["encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey"]]
        | Omit = omit,
        key_base64: str | Omit = omit,
        key_jwk: object | 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,
    ) -> Optional[SecretUpdateResponse]:
        if not account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        return cast(
            Optional[SecretUpdateResponse],
            self._put(
                path_template(
                    "/accounts/{account_id}/workers/scripts/{script_name}/secrets",
                    account_id=account_id,
                    script_name=script_name,
                ),
                body=maybe_transform(
                    {
                        "name": name,
                        "text": text,
                        "type": type,
                        "algorithm": algorithm,
                        "format": format,
                        "usages": usages,
                        "key_base64": key_base64,
                        "key_jwk": key_jwk,
                    },
                    secret_update_params.SecretUpdateParams,
                ),
                options=make_request_options(
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    timeout=timeout,
                    post_parser=ResultWrapper[Optional[SecretUpdateResponse]]._unwrapper,
                ),
                cast_to=cast(
                    Any, ResultWrapper[SecretUpdateResponse]
                ),  # Union types cannot be passed in as arguments in the type system
            ),
        )

    def list(
        self,
        script_name: str,
        *,
        account_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,
    ) -> SyncSinglePage[SecretListResponse]:
        """
        List secrets bound to a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        return self._get_api_list(
            path_template(
                "/accounts/{account_id}/workers/scripts/{script_name}/secrets",
                account_id=account_id,
                script_name=script_name,
            ),
            page=SyncSinglePage[SecretListResponse],
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            model=cast(Any, SecretListResponse),  # Union types cannot be passed in as arguments in the type system
        )

    def delete(
        self,
        secret_name: str,
        *,
        account_id: str,
        script_name: str,
        url_encoded: bool | 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,
    ) -> object:
        """
        Remove a secret from a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          secret_name: A JavaScript variable name for the secret binding.

          url_encoded: Flag that indicates whether the secret name is URL encoded.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        if not secret_name:
            raise ValueError(f"Expected a non-empty value for `secret_name` but received {secret_name!r}")
        return self._delete(
            path_template(
                "/accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}",
                account_id=account_id,
                script_name=script_name,
                secret_name=secret_name,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform({"url_encoded": url_encoded}, secret_delete_params.SecretDeleteParams),
                post_parser=ResultWrapper[Optional[object]]._unwrapper,
            ),
            cast_to=cast(Type[object], ResultWrapper[object]),
        )

    def bulk_update(
        self,
        script_name: str,
        *,
        account_id: str,
        secrets: Dict[str, Optional[secret_bulk_update_params.Secrets]] | Omit = omit,
        version_tags: Dict[str, object] | 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,
    ) -> Optional[SecretBulkUpdateResponse]:
        """
        Create, update, or delete multiple secrets on a script in a single operation
        using JSON Merge Patch (RFC 7396).

        Usage:

        - To create or update a secret, set its value to a secret object.
        - To delete a secret, set its value to `null`.
        - Secrets not included in the request are left unchanged.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          secrets:
              Map of secret names to secret values:

              - Set to a secret object to create or update.
              - Set to `null` to delete.
              - Omit to leave unchanged.

          version_tags: Optional version tags to apply to the new script version.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        return self._patch(
            path_template(
                "/accounts/{account_id}/workers/scripts/{script_name}/secrets-bulk",
                account_id=account_id,
                script_name=script_name,
            ),
            body=maybe_transform(
                {
                    "secrets": secrets,
                    "version_tags": version_tags,
                },
                secret_bulk_update_params.SecretBulkUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                post_parser=ResultWrapper[Optional[SecretBulkUpdateResponse]]._unwrapper,
            ),
            cast_to=cast(Type[Optional[SecretBulkUpdateResponse]], ResultWrapper[SecretBulkUpdateResponse]),
        )

    def get(
        self,
        secret_name: str,
        *,
        account_id: str,
        script_name: str,
        url_encoded: bool | 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,
    ) -> Optional[SecretGetResponse]:
        """
        Get a given secret binding (value omitted) on a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          secret_name: A JavaScript variable name for the secret binding.

          url_encoded: Flag that indicates whether the secret name is URL encoded.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        if not secret_name:
            raise ValueError(f"Expected a non-empty value for `secret_name` but received {secret_name!r}")
        return cast(
            Optional[SecretGetResponse],
            self._get(
                path_template(
                    "/accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}",
                    account_id=account_id,
                    script_name=script_name,
                    secret_name=secret_name,
                ),
                options=make_request_options(
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    timeout=timeout,
                    query=maybe_transform({"url_encoded": url_encoded}, secret_get_params.SecretGetParams),
                    post_parser=ResultWrapper[Optional[SecretGetResponse]]._unwrapper,
                ),
                cast_to=cast(
                    Any, ResultWrapper[SecretGetResponse]
                ),  # Union types cannot be passed in as arguments in the type system
            ),
        )


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

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

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

    @overload
    async def update(
        self,
        script_name: str,
        *,
        account_id: str,
        name: str,
        text: str,
        type: Literal["secret_text"],
        # 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,
    ) -> Optional[SecretUpdateResponse]:
        """
        Add a secret to a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          name: A JavaScript variable name for the binding.

          text: The secret value to use.

          type: The kind of resource that the binding provides.

          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
        """
        ...

    @overload
    async def update(
        self,
        script_name: str,
        *,
        account_id: str,
        algorithm: object,
        format: Literal["raw", "pkcs8", "spki", "jwk"],
        name: str,
        type: Literal["secret_key"],
        usages: List[
            Literal["encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey"]
        ],
        key_base64: str | Omit = omit,
        key_jwk: object | 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,
    ) -> Optional[SecretUpdateResponse]:
        """
        Add a secret to a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          algorithm: Algorithm-specific key parameters.
              [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#algorithm).

          format: Data format of the key.
              [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#format).

          name: A JavaScript variable name for the binding.

          type: The kind of resource that the binding provides.

          usages: Allowed operations with the key.
              [Learn more](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#keyUsages).

          key_base64: Base64-encoded key data. Required if `format` is "raw", "pkcs8", or "spki".

          key_jwk: Key data in
              [JSON Web Key](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey#json_web_key)
              format. Required if `format` is "jwk".

          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
        """
        ...

    @required_args(
        ["account_id", "name", "text", "type"], ["account_id", "algorithm", "format", "name", "type", "usages"]
    )
    async def update(
        self,
        script_name: str,
        *,
        account_id: str,
        name: str,
        text: str | Omit = omit,
        type: Literal["secret_text"] | Literal["secret_key"],
        algorithm: object | Omit = omit,
        format: Literal["raw", "pkcs8", "spki", "jwk"] | Omit = omit,
        usages: List[Literal["encrypt", "decrypt", "sign", "verify", "deriveKey", "deriveBits", "wrapKey", "unwrapKey"]]
        | Omit = omit,
        key_base64: str | Omit = omit,
        key_jwk: object | 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,
    ) -> Optional[SecretUpdateResponse]:
        if not account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        return cast(
            Optional[SecretUpdateResponse],
            await self._put(
                path_template(
                    "/accounts/{account_id}/workers/scripts/{script_name}/secrets",
                    account_id=account_id,
                    script_name=script_name,
                ),
                body=await async_maybe_transform(
                    {
                        "name": name,
                        "text": text,
                        "type": type,
                        "algorithm": algorithm,
                        "format": format,
                        "usages": usages,
                        "key_base64": key_base64,
                        "key_jwk": key_jwk,
                    },
                    secret_update_params.SecretUpdateParams,
                ),
                options=make_request_options(
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    timeout=timeout,
                    post_parser=ResultWrapper[Optional[SecretUpdateResponse]]._unwrapper,
                ),
                cast_to=cast(
                    Any, ResultWrapper[SecretUpdateResponse]
                ),  # Union types cannot be passed in as arguments in the type system
            ),
        )

    def list(
        self,
        script_name: str,
        *,
        account_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,
    ) -> AsyncPaginator[SecretListResponse, AsyncSinglePage[SecretListResponse]]:
        """
        List secrets bound to a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        return self._get_api_list(
            path_template(
                "/accounts/{account_id}/workers/scripts/{script_name}/secrets",
                account_id=account_id,
                script_name=script_name,
            ),
            page=AsyncSinglePage[SecretListResponse],
            options=make_request_options(
                extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
            ),
            model=cast(Any, SecretListResponse),  # Union types cannot be passed in as arguments in the type system
        )

    async def delete(
        self,
        secret_name: str,
        *,
        account_id: str,
        script_name: str,
        url_encoded: bool | 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,
    ) -> object:
        """
        Remove a secret from a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          secret_name: A JavaScript variable name for the secret binding.

          url_encoded: Flag that indicates whether the secret name is URL encoded.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        if not secret_name:
            raise ValueError(f"Expected a non-empty value for `secret_name` but received {secret_name!r}")
        return await self._delete(
            path_template(
                "/accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}",
                account_id=account_id,
                script_name=script_name,
                secret_name=secret_name,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=await async_maybe_transform(
                    {"url_encoded": url_encoded}, secret_delete_params.SecretDeleteParams
                ),
                post_parser=ResultWrapper[Optional[object]]._unwrapper,
            ),
            cast_to=cast(Type[object], ResultWrapper[object]),
        )

    async def bulk_update(
        self,
        script_name: str,
        *,
        account_id: str,
        secrets: Dict[str, Optional[secret_bulk_update_params.Secrets]] | Omit = omit,
        version_tags: Dict[str, object] | 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,
    ) -> Optional[SecretBulkUpdateResponse]:
        """
        Create, update, or delete multiple secrets on a script in a single operation
        using JSON Merge Patch (RFC 7396).

        Usage:

        - To create or update a secret, set its value to a secret object.
        - To delete a secret, set its value to `null`.
        - Secrets not included in the request are left unchanged.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          secrets:
              Map of secret names to secret values:

              - Set to a secret object to create or update.
              - Set to `null` to delete.
              - Omit to leave unchanged.

          version_tags: Optional version tags to apply to the new script version.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        return await self._patch(
            path_template(
                "/accounts/{account_id}/workers/scripts/{script_name}/secrets-bulk",
                account_id=account_id,
                script_name=script_name,
            ),
            body=await async_maybe_transform(
                {
                    "secrets": secrets,
                    "version_tags": version_tags,
                },
                secret_bulk_update_params.SecretBulkUpdateParams,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                post_parser=ResultWrapper[Optional[SecretBulkUpdateResponse]]._unwrapper,
            ),
            cast_to=cast(Type[Optional[SecretBulkUpdateResponse]], ResultWrapper[SecretBulkUpdateResponse]),
        )

    async def get(
        self,
        secret_name: str,
        *,
        account_id: str,
        script_name: str,
        url_encoded: bool | 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,
    ) -> Optional[SecretGetResponse]:
        """
        Get a given secret binding (value omitted) on a script.

        Args:
          account_id: Identifier.

          script_name: Name of the script, used in URLs and route configuration.

          secret_name: A JavaScript variable name for the secret binding.

          url_encoded: Flag that indicates whether the secret name is URL encoded.

          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 account_id:
            raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
        if not script_name:
            raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}")
        if not secret_name:
            raise ValueError(f"Expected a non-empty value for `secret_name` but received {secret_name!r}")
        return cast(
            Optional[SecretGetResponse],
            await self._get(
                path_template(
                    "/accounts/{account_id}/workers/scripts/{script_name}/secrets/{secret_name}",
                    account_id=account_id,
                    script_name=script_name,
                    secret_name=secret_name,
                ),
                options=make_request_options(
                    extra_headers=extra_headers,
                    extra_query=extra_query,
                    extra_body=extra_body,
                    timeout=timeout,
                    query=await async_maybe_transform({"url_encoded": url_encoded}, secret_get_params.SecretGetParams),
                    post_parser=ResultWrapper[Optional[SecretGetResponse]]._unwrapper,
                ),
                cast_to=cast(
                    Any, ResultWrapper[SecretGetResponse]
                ),  # Union types cannot be passed in as arguments in the type system
            ),
        )


class SecretsResourceWithRawResponse:
    def __init__(self, secrets: SecretsResource) -> None:
        self._secrets = secrets

        self.update = to_raw_response_wrapper(
            secrets.update,
        )
        self.list = to_raw_response_wrapper(
            secrets.list,
        )
        self.delete = to_raw_response_wrapper(
            secrets.delete,
        )
        self.bulk_update = to_raw_response_wrapper(
            secrets.bulk_update,
        )
        self.get = to_raw_response_wrapper(
            secrets.get,
        )


class AsyncSecretsResourceWithRawResponse:
    def __init__(self, secrets: AsyncSecretsResource) -> None:
        self._secrets = secrets

        self.update = async_to_raw_response_wrapper(
            secrets.update,
        )
        self.list = async_to_raw_response_wrapper(
            secrets.list,
        )
        self.delete = async_to_raw_response_wrapper(
            secrets.delete,
        )
        self.bulk_update = async_to_raw_response_wrapper(
            secrets.bulk_update,
        )
        self.get = async_to_raw_response_wrapper(
            secrets.get,
        )


class SecretsResourceWithStreamingResponse:
    def __init__(self, secrets: SecretsResource) -> None:
        self._secrets = secrets

        self.update = to_streamed_response_wrapper(
            secrets.update,
        )
        self.list = to_streamed_response_wrapper(
            secrets.list,
        )
        self.delete = to_streamed_response_wrapper(
            secrets.delete,
        )
        self.bulk_update = to_streamed_response_wrapper(
            secrets.bulk_update,
        )
        self.get = to_streamed_response_wrapper(
            secrets.get,
        )


class AsyncSecretsResourceWithStreamingResponse:
    def __init__(self, secrets: AsyncSecretsResource) -> None:
        self._secrets = secrets

        self.update = async_to_streamed_response_wrapper(
            secrets.update,
        )
        self.list = async_to_streamed_response_wrapper(
            secrets.list,
        )
        self.delete = async_to_streamed_response_wrapper(
            secrets.delete,
        )
        self.bulk_update = async_to_streamed_response_wrapper(
            secrets.bulk_update,
        )
        self.get = async_to_streamed_response_wrapper(
            secrets.get,
        )
