# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.app_variant_response import AppVariantResponse
from ..types.app_variant_revision import AppVariantRevision
from ..types.config_dto import ConfigDto
from ..types.config_response_model import ConfigResponseModel
from ..types.http_validation_error import HttpValidationError
from ..types.reference_dto import ReferenceDto
from ..types.reference_request_model import ReferenceRequestModel
from .types.add_variant_from_base_and_config_response import (
    AddVariantFromBaseAndConfigResponse,
)

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawVariantsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def add_variant_from_base_and_config(
        self,
        *,
        base_id: str,
        new_variant_name: str,
        new_config_name: str,
        parameters: typing.Dict[str, typing.Optional[typing.Any]],
        commit_message: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AddVariantFromBaseAndConfigResponse]:
        """
        Add a new variant based on an existing one.
        Same as POST /config

        Args:
            payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.

        Raises:
            HTTPException: Raised if the variant could not be added or accessed.

        Returns:
            Union[AppVariantResponse, Any]: New variant details or exception.

        Parameters
        ----------
        base_id : str

        new_variant_name : str

        new_config_name : str

        parameters : typing.Dict[str, typing.Optional[typing.Any]]

        commit_message : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AddVariantFromBaseAndConfigResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/from-base",
            method="POST",
            json={
                "base_id": base_id,
                "new_variant_name": new_variant_name,
                "new_config_name": new_config_name,
                "parameters": parameters,
                "commit_message": commit_message,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddVariantFromBaseAndConfigResponse,
                    parse_obj_as(
                        type_=AddVariantFromBaseAndConfigResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def get_variant(
        self,
        variant_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AppVariantResponse]:
        """
        Parameters
        ----------
        variant_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AppVariantResponse]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AppVariantResponse,
                    parse_obj_as(
                        type_=AppVariantResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def mark_variant_as_hidden(
        self,
        variant_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.Optional[typing.Any]]:
        """
        Mark a variant as hidden from the UI.

        Arguments:
            app_variant -- AppVariant to remove

        Raises:
            HTTPException: If there is a problem removing the app variant

        Parameters
        ----------
        variant_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if _response is None or not _response.text.strip():
                return HttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def update_variant_parameters(
        self,
        variant_id: str,
        *,
        parameters: typing.Dict[str, typing.Optional[typing.Any]],
        commit_message: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.Optional[typing.Any]]:
        """
        Updates the parameters for an app variant.

        Args:
            variant_id (str): The ID of the app variant to update.
            payload (UpdateVariantParameterPayload): The payload containing the updated parameters.

        Raises:
            HTTPException: If there is an error while trying to update the app variant.

        Returns:
            JSONResponse: A JSON response containing the updated app variant parameters.

        Parameters
        ----------
        variant_id : str

        parameters : typing.Dict[str, typing.Optional[typing.Any]]

        commit_message : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/parameters",
            method="PUT",
            json={
                "parameters": parameters,
                "commit_message": commit_message,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if _response is None or not _response.text.strip():
                return HttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def update_variant_url(
        self,
        variant_id: str,
        *,
        url: str,
        update_variant_url_payload_variant_id: str,
        commit_message: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.Optional[typing.Any]]:
        """
        Updates the URL used in an app variant.

        Args:
            variant_id (str): The ID of the app variant to update.
            url (str): The URL to update.

        Raises:
            HTTPException: If an error occurs while trying to update the app variant.

        Returns:
            JSONResponse: A JSON response indicating whether the update was successful or not.

        Parameters
        ----------
        variant_id : str

        url : str

        update_variant_url_payload_variant_id : str

        commit_message : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/service",
            method="PUT",
            json={
                "url": url,
                "variant_id": update_variant_url_payload_variant_id,
                "commit_message": commit_message,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if _response is None or not _response.text.strip():
                return HttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def get_variant_revisions(
        self,
        variant_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.List[AppVariantRevision]]:
        """
        Parameters
        ----------
        variant_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.List[AppVariantRevision]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/revisions",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[AppVariantRevision],
                    parse_obj_as(
                        type_=typing.List[AppVariantRevision],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def get_variant_revision(
        self,
        variant_id: str,
        revision_number: int,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AppVariantRevision]:
        """
        Parameters
        ----------
        variant_id : str

        revision_number : int

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AppVariantRevision]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/revisions/{jsonable_encoder(revision_number)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AppVariantRevision,
                    parse_obj_as(
                        type_=AppVariantRevision,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def mark_variant_revision_as_hidden(
        self,
        variant_id: str,
        revision_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.Optional[typing.Any]]:
        """
        Mark a variant revision as hidden from the UI.

        Arguments:
            app_variant -- AppVariant to remove
            revision_id -- Revision ID to remove

        Raises:
            HTTPException: If there is a problem removing the app variant

        Parameters
        ----------
        variant_id : str

        revision_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/revisions/{jsonable_encoder(revision_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if _response is None or not _response.text.strip():
                return HttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_add(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        application_ref: ReferenceRequestModel,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        application_ref : ReferenceRequestModel

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/add",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_fetch(
        self,
        *,
        variant_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        environment_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ConfigResponseModel]:
        """
        Fetch configuration for a variant or environment.

        Either variant_ref OR environment_ref must be provided (if neither is provided,
        a default environment_ref with slug="production" will be used).

        For each reference object (variant_ref, environment_ref, application_ref):
        - Provide either 'slug' or 'id' field
        - 'version' is optional and can be set to null
        - If 'id' is provided, it will be used directly to fetch the resource
        - Otherwise, 'slug' will be used along with application_ref

        Returns:
            ConfigResponseModel: The configuration for the requested variant or environment.

        Raises:
            HTTPException: If the configuration is not found.

        Parameters
        ----------
        variant_ref : typing.Optional[ReferenceRequestModel]

        environment_ref : typing.Optional[ReferenceRequestModel]

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/fetch",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "environment_ref": convert_and_respect_annotation_metadata(
                    object_=environment_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_fork(
        self,
        *,
        variant_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        environment_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        variant_ref : typing.Optional[ReferenceRequestModel]

        environment_ref : typing.Optional[ReferenceRequestModel]

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/fork",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "environment_ref": convert_and_respect_annotation_metadata(
                    object_=environment_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_commit(
        self,
        *,
        config: ConfigDto,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        config : ConfigDto

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/commit",
            method="POST",
            json={
                "config": convert_and_respect_annotation_metadata(
                    object_=config, annotation=ConfigDto, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_deploy(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        environment_ref: ReferenceRequestModel,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        environment_ref : ReferenceRequestModel

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/deploy",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "environment_ref": convert_and_respect_annotation_metadata(
                    object_=environment_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_delete(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[int]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[int]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/delete",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    int,
                    parse_obj_as(
                        type_=int,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_list(
        self,
        *,
        application_ref: ReferenceDto,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.List[ConfigResponseModel]]:
        """
        Parameters
        ----------
        application_ref : ReferenceDto

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.List[ConfigResponseModel]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/list",
            method="POST",
            json={
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref, annotation=ReferenceDto, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[ConfigResponseModel],
                    parse_obj_as(
                        type_=typing.List[ConfigResponseModel],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    def configs_history(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[typing.List[ConfigResponseModel]]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[typing.List[ConfigResponseModel]]
            Successful Response
        """
        _response = self._client_wrapper.httpx_client.request(
            "variants/configs/history",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[ConfigResponseModel],
                    parse_obj_as(
                        type_=typing.List[ConfigResponseModel],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )


class AsyncRawVariantsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def add_variant_from_base_and_config(
        self,
        *,
        base_id: str,
        new_variant_name: str,
        new_config_name: str,
        parameters: typing.Dict[str, typing.Optional[typing.Any]],
        commit_message: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AddVariantFromBaseAndConfigResponse]:
        """
        Add a new variant based on an existing one.
        Same as POST /config

        Args:
            payload (AddVariantFromBasePayload): Payload containing base variant ID, new variant name, and parameters.

        Raises:
            HTTPException: Raised if the variant could not be added or accessed.

        Returns:
            Union[AppVariantResponse, Any]: New variant details or exception.

        Parameters
        ----------
        base_id : str

        new_variant_name : str

        new_config_name : str

        parameters : typing.Dict[str, typing.Optional[typing.Any]]

        commit_message : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AddVariantFromBaseAndConfigResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/from-base",
            method="POST",
            json={
                "base_id": base_id,
                "new_variant_name": new_variant_name,
                "new_config_name": new_config_name,
                "parameters": parameters,
                "commit_message": commit_message,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddVariantFromBaseAndConfigResponse,
                    parse_obj_as(
                        type_=AddVariantFromBaseAndConfigResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def get_variant(
        self,
        variant_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AppVariantResponse]:
        """
        Parameters
        ----------
        variant_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AppVariantResponse]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AppVariantResponse,
                    parse_obj_as(
                        type_=AppVariantResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def mark_variant_as_hidden(
        self,
        variant_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.Optional[typing.Any]]:
        """
        Mark a variant as hidden from the UI.

        Arguments:
            app_variant -- AppVariant to remove

        Raises:
            HTTPException: If there is a problem removing the app variant

        Parameters
        ----------
        variant_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if _response is None or not _response.text.strip():
                return AsyncHttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def update_variant_parameters(
        self,
        variant_id: str,
        *,
        parameters: typing.Dict[str, typing.Optional[typing.Any]],
        commit_message: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.Optional[typing.Any]]:
        """
        Updates the parameters for an app variant.

        Args:
            variant_id (str): The ID of the app variant to update.
            payload (UpdateVariantParameterPayload): The payload containing the updated parameters.

        Raises:
            HTTPException: If there is an error while trying to update the app variant.

        Returns:
            JSONResponse: A JSON response containing the updated app variant parameters.

        Parameters
        ----------
        variant_id : str

        parameters : typing.Dict[str, typing.Optional[typing.Any]]

        commit_message : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/parameters",
            method="PUT",
            json={
                "parameters": parameters,
                "commit_message": commit_message,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if _response is None or not _response.text.strip():
                return AsyncHttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def update_variant_url(
        self,
        variant_id: str,
        *,
        url: str,
        update_variant_url_payload_variant_id: str,
        commit_message: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.Optional[typing.Any]]:
        """
        Updates the URL used in an app variant.

        Args:
            variant_id (str): The ID of the app variant to update.
            url (str): The URL to update.

        Raises:
            HTTPException: If an error occurs while trying to update the app variant.

        Returns:
            JSONResponse: A JSON response indicating whether the update was successful or not.

        Parameters
        ----------
        variant_id : str

        url : str

        update_variant_url_payload_variant_id : str

        commit_message : typing.Optional[str]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/service",
            method="PUT",
            json={
                "url": url,
                "variant_id": update_variant_url_payload_variant_id,
                "commit_message": commit_message,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if _response is None or not _response.text.strip():
                return AsyncHttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def get_variant_revisions(
        self,
        variant_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.List[AppVariantRevision]]:
        """
        Parameters
        ----------
        variant_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.List[AppVariantRevision]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/revisions",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[AppVariantRevision],
                    parse_obj_as(
                        type_=typing.List[AppVariantRevision],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def get_variant_revision(
        self,
        variant_id: str,
        revision_number: int,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AppVariantRevision]:
        """
        Parameters
        ----------
        variant_id : str

        revision_number : int

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AppVariantRevision]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/revisions/{jsonable_encoder(revision_number)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AppVariantRevision,
                    parse_obj_as(
                        type_=AppVariantRevision,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def mark_variant_revision_as_hidden(
        self,
        variant_id: str,
        revision_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.Optional[typing.Any]]:
        """
        Mark a variant revision as hidden from the UI.

        Arguments:
            app_variant -- AppVariant to remove
            revision_id -- Revision ID to remove

        Raises:
            HTTPException: If there is a problem removing the app variant

        Parameters
        ----------
        variant_id : str

        revision_id : str

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.Optional[typing.Any]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"variants/{jsonable_encoder(variant_id)}/revisions/{jsonable_encoder(revision_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if _response is None or not _response.text.strip():
                return AsyncHttpResponse(response=_response, data=None)
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.Optional[typing.Any],
                    parse_obj_as(
                        type_=typing.Optional[typing.Any],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_add(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        application_ref: ReferenceRequestModel,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        application_ref : ReferenceRequestModel

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/add",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_fetch(
        self,
        *,
        variant_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        environment_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ConfigResponseModel]:
        """
        Fetch configuration for a variant or environment.

        Either variant_ref OR environment_ref must be provided (if neither is provided,
        a default environment_ref with slug="production" will be used).

        For each reference object (variant_ref, environment_ref, application_ref):
        - Provide either 'slug' or 'id' field
        - 'version' is optional and can be set to null
        - If 'id' is provided, it will be used directly to fetch the resource
        - Otherwise, 'slug' will be used along with application_ref

        Returns:
            ConfigResponseModel: The configuration for the requested variant or environment.

        Raises:
            HTTPException: If the configuration is not found.

        Parameters
        ----------
        variant_ref : typing.Optional[ReferenceRequestModel]

        environment_ref : typing.Optional[ReferenceRequestModel]

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/fetch",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "environment_ref": convert_and_respect_annotation_metadata(
                    object_=environment_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_fork(
        self,
        *,
        variant_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        environment_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        variant_ref : typing.Optional[ReferenceRequestModel]

        environment_ref : typing.Optional[ReferenceRequestModel]

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/fork",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "environment_ref": convert_and_respect_annotation_metadata(
                    object_=environment_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_commit(
        self,
        *,
        config: ConfigDto,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        config : ConfigDto

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/commit",
            method="POST",
            json={
                "config": convert_and_respect_annotation_metadata(
                    object_=config, annotation=ConfigDto, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_deploy(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        environment_ref: ReferenceRequestModel,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ConfigResponseModel]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        environment_ref : ReferenceRequestModel

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[ConfigResponseModel]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/deploy",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "environment_ref": convert_and_respect_annotation_metadata(
                    object_=environment_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ConfigResponseModel,
                    parse_obj_as(
                        type_=ConfigResponseModel,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_delete(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[int]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[int]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/delete",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    int,
                    parse_obj_as(
                        type_=int,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_list(
        self,
        *,
        application_ref: ReferenceDto,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.List[ConfigResponseModel]]:
        """
        Parameters
        ----------
        application_ref : ReferenceDto

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.List[ConfigResponseModel]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/list",
            method="POST",
            json={
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref, annotation=ReferenceDto, direction="write"
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[ConfigResponseModel],
                    parse_obj_as(
                        type_=typing.List[ConfigResponseModel],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )

    async def configs_history(
        self,
        *,
        variant_ref: ReferenceRequestModel,
        application_ref: typing.Optional[ReferenceRequestModel] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[typing.List[ConfigResponseModel]]:
        """
        Parameters
        ----------
        variant_ref : ReferenceRequestModel

        application_ref : typing.Optional[ReferenceRequestModel]

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[typing.List[ConfigResponseModel]]
            Successful Response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "variants/configs/history",
            method="POST",
            json={
                "variant_ref": convert_and_respect_annotation_metadata(
                    object_=variant_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
                "application_ref": convert_and_respect_annotation_metadata(
                    object_=application_ref,
                    annotation=ReferenceRequestModel,
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    typing.List[ConfigResponseModel],
                    parse_obj_as(
                        type_=typing.List[ConfigResponseModel],  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        HttpValidationError,
                        parse_obj_as(
                            type_=HttpValidationError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(
                status_code=_response.status_code,
                headers=dict(_response.headers),
                body=_response.text,
            )
        raise ApiError(
            status_code=_response.status_code,
            headers=dict(_response.headers),
            body=_response_json,
        )
