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

import typing
from ..core.client_wrapper import SyncClientWrapper
from ..core.request_options import RequestOptions
from .types.update_company_plans_response import UpdateCompanyPlansResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..errors.bad_request_error import BadRequestError
from ..types.api_error import ApiError as types_api_error_ApiError
from ..errors.unauthorized_error import UnauthorizedError
from ..errors.forbidden_error import ForbiddenError
from ..errors.not_found_error import NotFoundError
from ..errors.internal_server_error import InternalServerError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError as core_api_error_ApiError
from .types.get_audience_response import GetAudienceResponse
from ..types.create_or_update_condition_group_request_body import (
    CreateOrUpdateConditionGroupRequestBody,
)
from ..types.create_or_update_condition_request_body import (
    CreateOrUpdateConditionRequestBody,
)
from .types.update_audience_response import UpdateAudienceResponse
from ..core.serialization import convert_and_respect_annotation_metadata
from .types.delete_audience_response import DeleteAudienceResponse
from .types.list_plans_request_plan_type import ListPlansRequestPlanType
from .types.list_plans_response import ListPlansResponse
from .types.create_plan_request_body_plan_type import CreatePlanRequestBodyPlanType
from .types.create_plan_response import CreatePlanResponse
from .types.get_plan_response import GetPlanResponse
from .types.update_plan_response import UpdatePlanResponse
from .types.delete_plan_response import DeletePlanResponse
from .types.upsert_billing_product_plan_response import UpsertBillingProductPlanResponse
from .types.count_plans_request_plan_type import CountPlansRequestPlanType
from .types.count_plans_response import CountPlansResponse
from ..core.client_wrapper import AsyncClientWrapper

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


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

    def update_company_plans(
        self,
        company_plan_id: str,
        *,
        add_on_ids: typing.Sequence[str],
        base_plan_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateCompanyPlansResponse:
        """
        Parameters
        ----------
        company_plan_id : str
            company_plan_id

        add_on_ids : typing.Sequence[str]

        base_plan_id : typing.Optional[str]

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

        Returns
        -------
        UpdateCompanyPlansResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.update_company_plans(
            company_plan_id="company_plan_id",
            add_on_ids=["add_on_ids"],
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"company-plans/{jsonable_encoder(company_plan_id)}",
            method="PUT",
            json={
                "add_on_ids": add_on_ids,
                "base_plan_id": base_plan_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpdateCompanyPlansResponse,
                    parse_obj_as(
                        type_=UpdateCompanyPlansResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def get_audience(
        self,
        plan_audience_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetAudienceResponse:
        """
        Parameters
        ----------
        plan_audience_id : str
            plan_audience_id

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

        Returns
        -------
        GetAudienceResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.get_audience(
            plan_audience_id="plan_audience_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plan-audiences/{jsonable_encoder(plan_audience_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GetAudienceResponse,
                    parse_obj_as(
                        type_=GetAudienceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def update_audience(
        self,
        plan_audience_id: str,
        *,
        condition_groups: typing.Sequence[CreateOrUpdateConditionGroupRequestBody],
        conditions: typing.Sequence[CreateOrUpdateConditionRequestBody],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateAudienceResponse:
        """
        Parameters
        ----------
        plan_audience_id : str
            plan_audience_id

        condition_groups : typing.Sequence[CreateOrUpdateConditionGroupRequestBody]

        conditions : typing.Sequence[CreateOrUpdateConditionRequestBody]

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

        Returns
        -------
        UpdateAudienceResponse
            OK

        Examples
        --------
        from schematic import (
            CreateOrUpdateConditionGroupRequestBody,
            CreateOrUpdateConditionRequestBody,
            Schematic,
        )

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.update_audience(
            plan_audience_id="plan_audience_id",
            condition_groups=[
                CreateOrUpdateConditionGroupRequestBody(
                    conditions=[
                        CreateOrUpdateConditionRequestBody(
                            condition_type="company",
                            operator="eq",
                            resource_ids=["resource_ids"],
                        )
                    ],
                )
            ],
            conditions=[
                CreateOrUpdateConditionRequestBody(
                    condition_type="company",
                    operator="eq",
                    resource_ids=["resource_ids"],
                )
            ],
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plan-audiences/{jsonable_encoder(plan_audience_id)}",
            method="PUT",
            json={
                "condition_groups": convert_and_respect_annotation_metadata(
                    object_=condition_groups,
                    annotation=typing.Sequence[CreateOrUpdateConditionGroupRequestBody],
                    direction="write",
                ),
                "conditions": convert_and_respect_annotation_metadata(
                    object_=conditions,
                    annotation=typing.Sequence[CreateOrUpdateConditionRequestBody],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpdateAudienceResponse,
                    parse_obj_as(
                        type_=UpdateAudienceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def delete_audience(
        self,
        plan_audience_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeleteAudienceResponse:
        """
        Parameters
        ----------
        plan_audience_id : str
            plan_audience_id

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

        Returns
        -------
        DeleteAudienceResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.delete_audience(
            plan_audience_id="plan_audience_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plan-audiences/{jsonable_encoder(plan_audience_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DeleteAudienceResponse,
                    parse_obj_as(
                        type_=DeleteAudienceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def list_plans(
        self,
        *,
        company_id: typing.Optional[str] = None,
        has_product_id: typing.Optional[bool] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        plan_type: typing.Optional[ListPlansRequestPlanType] = None,
        q: typing.Optional[str] = None,
        without_entitlement_for: typing.Optional[str] = None,
        without_product_id: typing.Optional[bool] = None,
        without_paid_product_id: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListPlansResponse:
        """
        Parameters
        ----------
        company_id : typing.Optional[str]

        has_product_id : typing.Optional[bool]
            Filter out plans that do not have a billing product ID

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        plan_type : typing.Optional[ListPlansRequestPlanType]
            Filter by plan type

        q : typing.Optional[str]

        without_entitlement_for : typing.Optional[str]
            Filter out plans that already have a plan entitlement for the specified feature ID

        without_product_id : typing.Optional[bool]
            Filter out plans that have a billing product ID

        without_paid_product_id : typing.Optional[bool]
            Filter out plans that have a paid billing product ID

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListPlansResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.list_plans()
        """
        _response = self._client_wrapper.httpx_client.request(
            "plans",
            method="GET",
            params={
                "company_id": company_id,
                "has_product_id": has_product_id,
                "ids": ids,
                "plan_type": plan_type,
                "q": q,
                "without_entitlement_for": without_entitlement_for,
                "without_product_id": without_product_id,
                "without_paid_product_id": without_paid_product_id,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ListPlansResponse,
                    parse_obj_as(
                        type_=ListPlansResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def create_plan(
        self,
        *,
        description: str,
        name: str,
        plan_type: CreatePlanRequestBodyPlanType,
        icon: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreatePlanResponse:
        """
        Parameters
        ----------
        description : str

        name : str

        plan_type : CreatePlanRequestBodyPlanType

        icon : typing.Optional[str]

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

        Returns
        -------
        CreatePlanResponse
            Created

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.create_plan(
            description="description",
            name="name",
            plan_type="plan",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "plans",
            method="POST",
            json={
                "description": description,
                "icon": icon,
                "name": name,
                "plan_type": plan_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    CreatePlanResponse,
                    parse_obj_as(
                        type_=CreatePlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def get_plan(self, plan_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> GetPlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

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

        Returns
        -------
        GetPlanResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.get_plan(
            plan_id="plan_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GetPlanResponse,
                    parse_obj_as(
                        type_=GetPlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def update_plan(
        self,
        plan_id: str,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        icon: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdatePlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

        name : str

        description : typing.Optional[str]

        icon : typing.Optional[str]

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

        Returns
        -------
        UpdatePlanResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.update_plan(
            plan_id="plan_id",
            name="name",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}",
            method="PUT",
            json={
                "description": description,
                "icon": icon,
                "name": name,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpdatePlanResponse,
                    parse_obj_as(
                        type_=UpdatePlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def delete_plan(
        self, plan_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeletePlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

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

        Returns
        -------
        DeletePlanResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.delete_plan(
            plan_id="plan_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DeletePlanResponse,
                    parse_obj_as(
                        type_=DeletePlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def upsert_billing_product_plan(
        self,
        plan_id: str,
        *,
        is_free_plan: bool,
        is_trialable: bool,
        billing_product_id: typing.Optional[str] = OMIT,
        monthly_price_id: typing.Optional[str] = OMIT,
        trial_days: typing.Optional[int] = OMIT,
        yearly_price_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertBillingProductPlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

        is_free_plan : bool

        is_trialable : bool

        billing_product_id : typing.Optional[str]

        monthly_price_id : typing.Optional[str]

        trial_days : typing.Optional[int]

        yearly_price_id : typing.Optional[str]

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

        Returns
        -------
        UpsertBillingProductPlanResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.upsert_billing_product_plan(
            plan_id="plan_id",
            is_free_plan=True,
            is_trialable=True,
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}/billing_products",
            method="PUT",
            json={
                "billing_product_id": billing_product_id,
                "is_free_plan": is_free_plan,
                "is_trialable": is_trialable,
                "monthly_price_id": monthly_price_id,
                "trial_days": trial_days,
                "yearly_price_id": yearly_price_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpsertBillingProductPlanResponse,
                    parse_obj_as(
                        type_=UpsertBillingProductPlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    def count_plans(
        self,
        *,
        company_id: typing.Optional[str] = None,
        has_product_id: typing.Optional[bool] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        plan_type: typing.Optional[CountPlansRequestPlanType] = None,
        q: typing.Optional[str] = None,
        without_entitlement_for: typing.Optional[str] = None,
        without_product_id: typing.Optional[bool] = None,
        without_paid_product_id: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CountPlansResponse:
        """
        Parameters
        ----------
        company_id : typing.Optional[str]

        has_product_id : typing.Optional[bool]
            Filter out plans that do not have a billing product ID

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        plan_type : typing.Optional[CountPlansRequestPlanType]
            Filter by plan type

        q : typing.Optional[str]

        without_entitlement_for : typing.Optional[str]
            Filter out plans that already have a plan entitlement for the specified feature ID

        without_product_id : typing.Optional[bool]
            Filter out plans that have a billing product ID

        without_paid_product_id : typing.Optional[bool]
            Filter out plans that have a paid billing product ID

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        CountPlansResponse
            OK

        Examples
        --------
        from schematic import Schematic

        client = Schematic(
            api_key="YOUR_API_KEY",
        )
        client.plans.count_plans()
        """
        _response = self._client_wrapper.httpx_client.request(
            "plans/count",
            method="GET",
            params={
                "company_id": company_id,
                "has_product_id": has_product_id,
                "ids": ids,
                "plan_type": plan_type,
                "q": q,
                "without_entitlement_for": without_entitlement_for,
                "without_product_id": without_product_id,
                "without_paid_product_id": without_paid_product_id,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    CountPlansResponse,
                    parse_obj_as(
                        type_=CountPlansResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)


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

    async def update_company_plans(
        self,
        company_plan_id: str,
        *,
        add_on_ids: typing.Sequence[str],
        base_plan_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateCompanyPlansResponse:
        """
        Parameters
        ----------
        company_plan_id : str
            company_plan_id

        add_on_ids : typing.Sequence[str]

        base_plan_id : typing.Optional[str]

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

        Returns
        -------
        UpdateCompanyPlansResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.update_company_plans(
                company_plan_id="company_plan_id",
                add_on_ids=["add_on_ids"],
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"company-plans/{jsonable_encoder(company_plan_id)}",
            method="PUT",
            json={
                "add_on_ids": add_on_ids,
                "base_plan_id": base_plan_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpdateCompanyPlansResponse,
                    parse_obj_as(
                        type_=UpdateCompanyPlansResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def get_audience(
        self,
        plan_audience_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetAudienceResponse:
        """
        Parameters
        ----------
        plan_audience_id : str
            plan_audience_id

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

        Returns
        -------
        GetAudienceResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.get_audience(
                plan_audience_id="plan_audience_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plan-audiences/{jsonable_encoder(plan_audience_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GetAudienceResponse,
                    parse_obj_as(
                        type_=GetAudienceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def update_audience(
        self,
        plan_audience_id: str,
        *,
        condition_groups: typing.Sequence[CreateOrUpdateConditionGroupRequestBody],
        conditions: typing.Sequence[CreateOrUpdateConditionRequestBody],
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdateAudienceResponse:
        """
        Parameters
        ----------
        plan_audience_id : str
            plan_audience_id

        condition_groups : typing.Sequence[CreateOrUpdateConditionGroupRequestBody]

        conditions : typing.Sequence[CreateOrUpdateConditionRequestBody]

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

        Returns
        -------
        UpdateAudienceResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import (
            AsyncSchematic,
            CreateOrUpdateConditionGroupRequestBody,
            CreateOrUpdateConditionRequestBody,
        )

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.update_audience(
                plan_audience_id="plan_audience_id",
                condition_groups=[
                    CreateOrUpdateConditionGroupRequestBody(
                        conditions=[
                            CreateOrUpdateConditionRequestBody(
                                condition_type="company",
                                operator="eq",
                                resource_ids=["resource_ids"],
                            )
                        ],
                    )
                ],
                conditions=[
                    CreateOrUpdateConditionRequestBody(
                        condition_type="company",
                        operator="eq",
                        resource_ids=["resource_ids"],
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plan-audiences/{jsonable_encoder(plan_audience_id)}",
            method="PUT",
            json={
                "condition_groups": convert_and_respect_annotation_metadata(
                    object_=condition_groups,
                    annotation=typing.Sequence[CreateOrUpdateConditionGroupRequestBody],
                    direction="write",
                ),
                "conditions": convert_and_respect_annotation_metadata(
                    object_=conditions,
                    annotation=typing.Sequence[CreateOrUpdateConditionRequestBody],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpdateAudienceResponse,
                    parse_obj_as(
                        type_=UpdateAudienceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def delete_audience(
        self,
        plan_audience_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DeleteAudienceResponse:
        """
        Parameters
        ----------
        plan_audience_id : str
            plan_audience_id

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

        Returns
        -------
        DeleteAudienceResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.delete_audience(
                plan_audience_id="plan_audience_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plan-audiences/{jsonable_encoder(plan_audience_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DeleteAudienceResponse,
                    parse_obj_as(
                        type_=DeleteAudienceResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def list_plans(
        self,
        *,
        company_id: typing.Optional[str] = None,
        has_product_id: typing.Optional[bool] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        plan_type: typing.Optional[ListPlansRequestPlanType] = None,
        q: typing.Optional[str] = None,
        without_entitlement_for: typing.Optional[str] = None,
        without_product_id: typing.Optional[bool] = None,
        without_paid_product_id: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListPlansResponse:
        """
        Parameters
        ----------
        company_id : typing.Optional[str]

        has_product_id : typing.Optional[bool]
            Filter out plans that do not have a billing product ID

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        plan_type : typing.Optional[ListPlansRequestPlanType]
            Filter by plan type

        q : typing.Optional[str]

        without_entitlement_for : typing.Optional[str]
            Filter out plans that already have a plan entitlement for the specified feature ID

        without_product_id : typing.Optional[bool]
            Filter out plans that have a billing product ID

        without_paid_product_id : typing.Optional[bool]
            Filter out plans that have a paid billing product ID

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        ListPlansResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.list_plans()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "plans",
            method="GET",
            params={
                "company_id": company_id,
                "has_product_id": has_product_id,
                "ids": ids,
                "plan_type": plan_type,
                "q": q,
                "without_entitlement_for": without_entitlement_for,
                "without_product_id": without_product_id,
                "without_paid_product_id": without_paid_product_id,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    ListPlansResponse,
                    parse_obj_as(
                        type_=ListPlansResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def create_plan(
        self,
        *,
        description: str,
        name: str,
        plan_type: CreatePlanRequestBodyPlanType,
        icon: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreatePlanResponse:
        """
        Parameters
        ----------
        description : str

        name : str

        plan_type : CreatePlanRequestBodyPlanType

        icon : typing.Optional[str]

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

        Returns
        -------
        CreatePlanResponse
            Created

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.create_plan(
                description="description",
                name="name",
                plan_type="plan",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "plans",
            method="POST",
            json={
                "description": description,
                "icon": icon,
                "name": name,
                "plan_type": plan_type,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    CreatePlanResponse,
                    parse_obj_as(
                        type_=CreatePlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def get_plan(
        self, plan_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> GetPlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

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

        Returns
        -------
        GetPlanResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.get_plan(
                plan_id="plan_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    GetPlanResponse,
                    parse_obj_as(
                        type_=GetPlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def update_plan(
        self,
        plan_id: str,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        icon: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpdatePlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

        name : str

        description : typing.Optional[str]

        icon : typing.Optional[str]

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

        Returns
        -------
        UpdatePlanResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.update_plan(
                plan_id="plan_id",
                name="name",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}",
            method="PUT",
            json={
                "description": description,
                "icon": icon,
                "name": name,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpdatePlanResponse,
                    parse_obj_as(
                        type_=UpdatePlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def delete_plan(
        self, plan_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeletePlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

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

        Returns
        -------
        DeletePlanResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.delete_plan(
                plan_id="plan_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    DeletePlanResponse,
                    parse_obj_as(
                        type_=DeletePlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def upsert_billing_product_plan(
        self,
        plan_id: str,
        *,
        is_free_plan: bool,
        is_trialable: bool,
        billing_product_id: typing.Optional[str] = OMIT,
        monthly_price_id: typing.Optional[str] = OMIT,
        trial_days: typing.Optional[int] = OMIT,
        yearly_price_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UpsertBillingProductPlanResponse:
        """
        Parameters
        ----------
        plan_id : str
            plan_id

        is_free_plan : bool

        is_trialable : bool

        billing_product_id : typing.Optional[str]

        monthly_price_id : typing.Optional[str]

        trial_days : typing.Optional[int]

        yearly_price_id : typing.Optional[str]

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

        Returns
        -------
        UpsertBillingProductPlanResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.upsert_billing_product_plan(
                plan_id="plan_id",
                is_free_plan=True,
                is_trialable=True,
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"plans/{jsonable_encoder(plan_id)}/billing_products",
            method="PUT",
            json={
                "billing_product_id": billing_product_id,
                "is_free_plan": is_free_plan,
                "is_trialable": is_trialable,
                "monthly_price_id": monthly_price_id,
                "trial_days": trial_days,
                "yearly_price_id": yearly_price_id,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    UpsertBillingProductPlanResponse,
                    parse_obj_as(
                        type_=UpsertBillingProductPlanResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)

    async def count_plans(
        self,
        *,
        company_id: typing.Optional[str] = None,
        has_product_id: typing.Optional[bool] = None,
        ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        plan_type: typing.Optional[CountPlansRequestPlanType] = None,
        q: typing.Optional[str] = None,
        without_entitlement_for: typing.Optional[str] = None,
        without_product_id: typing.Optional[bool] = None,
        without_paid_product_id: typing.Optional[bool] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CountPlansResponse:
        """
        Parameters
        ----------
        company_id : typing.Optional[str]

        has_product_id : typing.Optional[bool]
            Filter out plans that do not have a billing product ID

        ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]

        plan_type : typing.Optional[CountPlansRequestPlanType]
            Filter by plan type

        q : typing.Optional[str]

        without_entitlement_for : typing.Optional[str]
            Filter out plans that already have a plan entitlement for the specified feature ID

        without_product_id : typing.Optional[bool]
            Filter out plans that have a billing product ID

        without_paid_product_id : typing.Optional[bool]
            Filter out plans that have a paid billing product ID

        limit : typing.Optional[int]
            Page limit (default 100)

        offset : typing.Optional[int]
            Page offset (default 0)

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

        Returns
        -------
        CountPlansResponse
            OK

        Examples
        --------
        import asyncio

        from schematic import AsyncSchematic

        client = AsyncSchematic(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.plans.count_plans()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "plans/count",
            method="GET",
            params={
                "company_id": company_id,
                "has_product_id": has_product_id,
                "ids": ids,
                "plan_type": plan_type,
                "q": q,
                "without_entitlement_for": without_entitlement_for,
                "without_product_id": without_product_id,
                "without_paid_product_id": without_paid_product_id,
                "limit": limit,
                "offset": offset,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    CountPlansResponse,
                    parse_obj_as(
                        type_=CountPlansResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 400:
                raise BadRequestError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    typing.cast(
                        types_api_error_ApiError,
                        parse_obj_as(
                            type_=types_api_error_ApiError,  # type: ignore
                            object_=_response.json(),
                        ),
                    )
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise core_api_error_ApiError(status_code=_response.status_code, body=_response.text)
        raise core_api_error_ApiError(status_code=_response.status_code, body=_response_json)
