# 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.bad_request_error import BadRequestError
from ..errors.conflict_error import ConflictError
from ..errors.forbidden_error import ForbiddenError
from ..errors.not_found_error import NotFoundError
from ..errors.unauthorized_error import UnauthorizedError
from ..errors.unprocessable_entity_error import UnprocessableEntityError
from ..types.apply_mode import ApplyMode
from ..types.attachment_create_inline import AttachmentCreateInline
from ..types.entity_type import EntityType
from ..types.rule_category import RuleCategory
from ..types.rule_detail_response import RuleDetailResponse
from ..types.rule_list_paginated_response import RuleListPaginatedResponse
from ..types.rule_scope import RuleScope
from ..types.rule_scope_api import RuleScopeApi
from ..types.rule_type import RuleType

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


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

    def list_rules(
        self,
        org_id: str,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        category: typing.Optional[RuleCategory] = None,
        rule_type: typing.Optional[RuleType] = None,
        scope: typing.Optional[RuleScope] = None,
        is_active: typing.Optional[bool] = None,
        is_public: typing.Optional[bool] = None,
        entity_type: typing.Optional[EntityType] = None,
        entity_id: typing.Optional[str] = None,
        attached_only: typing.Optional[bool] = None,
        include_attachments: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[RuleListPaginatedResponse]:
        """
        List all rules in an organization with pagination, filtering, and search.

        Parameters
        ----------
        org_id : str

        skip : typing.Optional[int]
            Number of records to skip for pagination

        limit : typing.Optional[int]
            Maximum number of records to return (1-100)

        search : typing.Optional[str]
            Search query to match against name, description, and content

        category : typing.Optional[RuleCategory]
            Filter by category (safety, professional, creative, technical, custom)

        rule_type : typing.Optional[RuleType]
            Filter by rule type (behavior, guardrails, formatting, context, content_policy, constraint)

        scope : typing.Optional[RuleScope]
            Filter by scope (global, organization, model, assistant, user, vector_store)

        is_active : typing.Optional[bool]
            Filter by active status (true/false)

        is_public : typing.Optional[bool]
            Filter by public status (true/false)

        entity_type : typing.Optional[EntityType]
            Filter by entity type (assistant, vector_store, user, model, organization)

        entity_id : typing.Optional[str]
            Filter by specific entity ID (e.g., asst_123, vs_456). Requires entity_type if provided.

        attached_only : typing.Optional[bool]
            Filter by attachment status - true: only attached rules, false: only unattached rules

        include_attachments : typing.Optional[bool]
            Include list of attached entities with priority in response

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

        Returns
        -------
        HttpResponse[RuleListPaginatedResponse]
            Rules retrieved successfully
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/organizations/{jsonable_encoder(org_id)}/rules",
            method="GET",
            params={
                "skip": skip,
                "limit": limit,
                "search": search,
                "category": category,
                "rule_type": rule_type,
                "scope": scope,
                "is_active": is_active,
                "is_public": is_public,
                "entity_type": entity_type,
                "entity_id": entity_id,
                "attached_only": attached_only,
                "include_attachments": include_attachments,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleListPaginatedResponse,
                    parse_obj_as(
                        type_=RuleListPaginatedResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 create_rule(
        self,
        org_id: str,
        *,
        name: str,
        content: str,
        description: typing.Optional[str] = OMIT,
        category: typing.Optional[RuleCategory] = OMIT,
        rule_type: typing.Optional[RuleType] = OMIT,
        scope: typing.Optional[RuleScopeApi] = OMIT,
        apply_mode: typing.Optional[ApplyMode] = OMIT,
        is_public: typing.Optional[bool] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        attachments: typing.Optional[typing.Sequence[AttachmentCreateInline]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[RuleDetailResponse]:
        """
        Create a new rule within an organization. The creator automatically receives owner access.

        Parameters
        ----------
        org_id : str

        name : str
            Rule name

        content : str
            Rule content (max 50KB)

        description : typing.Optional[str]
            Rule description

        category : typing.Optional[RuleCategory]
            Rule category

        rule_type : typing.Optional[RuleType]
            Rule type

        scope : typing.Optional[RuleScopeApi]
            Rule scope (global scope restricted - admin only)

        apply_mode : typing.Optional[ApplyMode]
            Rule apply mode

        is_public : typing.Optional[bool]
            Whether rule is public

        is_active : typing.Optional[bool]
            Whether rule is active

        attachments : typing.Optional[typing.Sequence[AttachmentCreateInline]]
            Optional list of entities to attach to this rule upon creation

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

        Returns
        -------
        HttpResponse[RuleDetailResponse]
            Rule created successfully
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/organizations/{jsonable_encoder(org_id)}/rules",
            method="POST",
            json={
                "name": name,
                "content": content,
                "description": description,
                "category": category,
                "rule_type": rule_type,
                "scope": scope,
                "apply_mode": apply_mode,
                "is_public": is_public,
                "is_active": is_active,
                "attachments": convert_and_respect_annotation_metadata(
                    object_=attachments,
                    annotation=typing.Optional[typing.Sequence[AttachmentCreateInline]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleDetailResponse,
                    parse_obj_as(
                        type_=RuleDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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_rule(
        self,
        org_id: str,
        rule_id: str,
        *,
        include_attachments: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[RuleDetailResponse]:
        """
        Get complete details of a specific rule including full content.

        Parameters
        ----------
        org_id : str

        rule_id : str

        include_attachments : typing.Optional[bool]
            Include list of attached entities in response

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

        Returns
        -------
        HttpResponse[RuleDetailResponse]
            Rule details retrieved successfully
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/organizations/{jsonable_encoder(org_id)}/rules/{jsonable_encoder(rule_id)}",
            method="GET",
            params={
                "include_attachments": include_attachments,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleDetailResponse,
                    parse_obj_as(
                        type_=RuleDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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_rule_global(
        self,
        rule_id: str,
        *,
        include_attachments: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[RuleDetailResponse]:
        """
        Get rule details by ID without requiring organization ID. Rule IDs are globally unique.

        Parameters
        ----------
        rule_id : str

        include_attachments : typing.Optional[bool]
            Include list of attached entities in response

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

        Returns
        -------
        HttpResponse[RuleDetailResponse]
            Rule details retrieved successfully
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/rules/{jsonable_encoder(rule_id)}",
            method="GET",
            params={
                "include_attachments": include_attachments,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleDetailResponse,
                    parse_obj_as(
                        type_=RuleDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 AsyncRawRulesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_rules(
        self,
        org_id: str,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        search: typing.Optional[str] = None,
        category: typing.Optional[RuleCategory] = None,
        rule_type: typing.Optional[RuleType] = None,
        scope: typing.Optional[RuleScope] = None,
        is_active: typing.Optional[bool] = None,
        is_public: typing.Optional[bool] = None,
        entity_type: typing.Optional[EntityType] = None,
        entity_id: typing.Optional[str] = None,
        attached_only: typing.Optional[bool] = None,
        include_attachments: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[RuleListPaginatedResponse]:
        """
        List all rules in an organization with pagination, filtering, and search.

        Parameters
        ----------
        org_id : str

        skip : typing.Optional[int]
            Number of records to skip for pagination

        limit : typing.Optional[int]
            Maximum number of records to return (1-100)

        search : typing.Optional[str]
            Search query to match against name, description, and content

        category : typing.Optional[RuleCategory]
            Filter by category (safety, professional, creative, technical, custom)

        rule_type : typing.Optional[RuleType]
            Filter by rule type (behavior, guardrails, formatting, context, content_policy, constraint)

        scope : typing.Optional[RuleScope]
            Filter by scope (global, organization, model, assistant, user, vector_store)

        is_active : typing.Optional[bool]
            Filter by active status (true/false)

        is_public : typing.Optional[bool]
            Filter by public status (true/false)

        entity_type : typing.Optional[EntityType]
            Filter by entity type (assistant, vector_store, user, model, organization)

        entity_id : typing.Optional[str]
            Filter by specific entity ID (e.g., asst_123, vs_456). Requires entity_type if provided.

        attached_only : typing.Optional[bool]
            Filter by attachment status - true: only attached rules, false: only unattached rules

        include_attachments : typing.Optional[bool]
            Include list of attached entities with priority in response

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

        Returns
        -------
        AsyncHttpResponse[RuleListPaginatedResponse]
            Rules retrieved successfully
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/organizations/{jsonable_encoder(org_id)}/rules",
            method="GET",
            params={
                "skip": skip,
                "limit": limit,
                "search": search,
                "category": category,
                "rule_type": rule_type,
                "scope": scope,
                "is_active": is_active,
                "is_public": is_public,
                "entity_type": entity_type,
                "entity_id": entity_id,
                "attached_only": attached_only,
                "include_attachments": include_attachments,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleListPaginatedResponse,
                    parse_obj_as(
                        type_=RuleListPaginatedResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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 create_rule(
        self,
        org_id: str,
        *,
        name: str,
        content: str,
        description: typing.Optional[str] = OMIT,
        category: typing.Optional[RuleCategory] = OMIT,
        rule_type: typing.Optional[RuleType] = OMIT,
        scope: typing.Optional[RuleScopeApi] = OMIT,
        apply_mode: typing.Optional[ApplyMode] = OMIT,
        is_public: typing.Optional[bool] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        attachments: typing.Optional[typing.Sequence[AttachmentCreateInline]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[RuleDetailResponse]:
        """
        Create a new rule within an organization. The creator automatically receives owner access.

        Parameters
        ----------
        org_id : str

        name : str
            Rule name

        content : str
            Rule content (max 50KB)

        description : typing.Optional[str]
            Rule description

        category : typing.Optional[RuleCategory]
            Rule category

        rule_type : typing.Optional[RuleType]
            Rule type

        scope : typing.Optional[RuleScopeApi]
            Rule scope (global scope restricted - admin only)

        apply_mode : typing.Optional[ApplyMode]
            Rule apply mode

        is_public : typing.Optional[bool]
            Whether rule is public

        is_active : typing.Optional[bool]
            Whether rule is active

        attachments : typing.Optional[typing.Sequence[AttachmentCreateInline]]
            Optional list of entities to attach to this rule upon creation

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

        Returns
        -------
        AsyncHttpResponse[RuleDetailResponse]
            Rule created successfully
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/organizations/{jsonable_encoder(org_id)}/rules",
            method="POST",
            json={
                "name": name,
                "content": content,
                "description": description,
                "category": category,
                "rule_type": rule_type,
                "scope": scope,
                "apply_mode": apply_mode,
                "is_public": is_public,
                "is_active": is_active,
                "attachments": convert_and_respect_annotation_metadata(
                    object_=attachments,
                    annotation=typing.Optional[typing.Sequence[AttachmentCreateInline]],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleDetailResponse,
                    parse_obj_as(
                        type_=RuleDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 409:
                raise ConflictError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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_rule(
        self,
        org_id: str,
        rule_id: str,
        *,
        include_attachments: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[RuleDetailResponse]:
        """
        Get complete details of a specific rule including full content.

        Parameters
        ----------
        org_id : str

        rule_id : str

        include_attachments : typing.Optional[bool]
            Include list of attached entities in response

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

        Returns
        -------
        AsyncHttpResponse[RuleDetailResponse]
            Rule details retrieved successfully
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/organizations/{jsonable_encoder(org_id)}/rules/{jsonable_encoder(rule_id)}",
            method="GET",
            params={
                "include_attachments": include_attachments,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleDetailResponse,
                    parse_obj_as(
                        type_=RuleDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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_rule_global(
        self,
        rule_id: str,
        *,
        include_attachments: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[RuleDetailResponse]:
        """
        Get rule details by ID without requiring organization ID. Rule IDs are globally unique.

        Parameters
        ----------
        rule_id : str

        include_attachments : typing.Optional[bool]
            Include list of attached entities in response

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

        Returns
        -------
        AsyncHttpResponse[RuleDetailResponse]
            Rule details retrieved successfully
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/rules/{jsonable_encoder(rule_id)}",
            method="GET",
            params={
                "include_attachments": include_attachments,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    RuleDetailResponse,
                    parse_obj_as(
                        type_=RuleDetailResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 422:
                raise UnprocessableEntityError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # 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)
