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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.attachment_delete_response import AttachmentDeleteResponse
from ..types.attachment_list_response import AttachmentListResponse
from ..types.attachment_response import AttachmentResponse
from ..types.entity_type import EntityType
from .raw_client import AsyncRawRuleAttachmentsClient, RawRuleAttachmentsClient

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


class RuleAttachmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRuleAttachmentsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawRuleAttachmentsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawRuleAttachmentsClient
        """
        return self._raw_client

    def list_rule_attachments(
        self,
        rule_id: str,
        *,
        entity_type: typing.Optional[str] = None,
        is_active: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttachmentListResponse:
        """
        List all entities attached to a rule, ordered by priority (descending).

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

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

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

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

        Returns
        -------
        AttachmentListResponse
            Attachments retrieved successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_attachments.list_rule_attachments(
            rule_id="rule_id",
        )
        """
        _response = self._raw_client.list_rule_attachments(
            rule_id, entity_type=entity_type, is_active=is_active, request_options=request_options
        )
        return _response.data

    def attach_entity(
        self,
        rule_id: str,
        *,
        entity_type: EntityType,
        entity_id: str,
        priority: typing.Optional[int] = OMIT,
        character_limit: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttachmentResponse:
        """
        Attach an entity (assistant, user, model, vector_store, organization) to a rule with configuration.

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

        entity_type : EntityType
            Type of entity to attach

        entity_id : str
            ID of entity to attach

        priority : typing.Optional[int]
            Priority (1-100, default 50)

        character_limit : typing.Optional[int]
            Character limit for rule content (100-50000)

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

        Returns
        -------
        AttachmentResponse
            Entity attached successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_attachments.attach_entity(
            rule_id="rule_id",
            entity_type="assistant",
            entity_id="asst_abc123",
        )
        """
        _response = self._raw_client.attach_entity(
            rule_id,
            entity_type=entity_type,
            entity_id=entity_id,
            priority=priority,
            character_limit=character_limit,
            request_options=request_options,
        )
        return _response.data

    def get_attachment(
        self, rule_id: str, entity_type: str, entity_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AttachmentResponse:
        """
        Get details of a specific attachment by rule, entity type, and entity ID.

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

        entity_type : str

        entity_id : str

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

        Returns
        -------
        AttachmentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_attachments.get_attachment(
            rule_id="rule_id",
            entity_type="entity_type",
            entity_id="entity_id",
        )
        """
        _response = self._raw_client.get_attachment(rule_id, entity_type, entity_id, request_options=request_options)
        return _response.data

    def update_attachment(
        self,
        rule_id: str,
        entity_type: str,
        entity_id: str,
        *,
        include_rule_details: typing.Optional[bool] = None,
        priority: typing.Optional[int] = OMIT,
        character_limit: typing.Optional[int] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttachmentResponse:
        """
        Update attachment configuration (priority, character limit, is_active).

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

        entity_type : str

        entity_id : str

        include_rule_details : typing.Optional[bool]
            Include rule summary (name, category) in response

        priority : typing.Optional[int]
            Priority (1-100)

        character_limit : typing.Optional[int]
            Character limit (100-50000)

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

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

        Returns
        -------
        AttachmentResponse
            Attachment updated successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_attachments.update_attachment(
            rule_id="rule_id",
            entity_type="entity_type",
            entity_id="entity_id",
        )
        """
        _response = self._raw_client.update_attachment(
            rule_id,
            entity_type,
            entity_id,
            include_rule_details=include_rule_details,
            priority=priority,
            character_limit=character_limit,
            is_active=is_active,
            request_options=request_options,
        )
        return _response.data

    def detach_entity(
        self, rule_id: str, entity_type: str, entity_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AttachmentDeleteResponse:
        """
        Remove an entity attachment from a rule (soft delete).

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

        entity_type : str

        entity_id : str

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

        Returns
        -------
        AttachmentDeleteResponse
            Entity detached successfully

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_attachments.detach_entity(
            rule_id="rule_id",
            entity_type="entity_type",
            entity_id="entity_id",
        )
        """
        _response = self._raw_client.detach_entity(rule_id, entity_type, entity_id, request_options=request_options)
        return _response.data


class AsyncRuleAttachmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRuleAttachmentsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawRuleAttachmentsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawRuleAttachmentsClient
        """
        return self._raw_client

    async def list_rule_attachments(
        self,
        rule_id: str,
        *,
        entity_type: typing.Optional[str] = None,
        is_active: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttachmentListResponse:
        """
        List all entities attached to a rule, ordered by priority (descending).

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

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

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

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

        Returns
        -------
        AttachmentListResponse
            Attachments retrieved successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_attachments.list_rule_attachments(
                rule_id="rule_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_rule_attachments(
            rule_id, entity_type=entity_type, is_active=is_active, request_options=request_options
        )
        return _response.data

    async def attach_entity(
        self,
        rule_id: str,
        *,
        entity_type: EntityType,
        entity_id: str,
        priority: typing.Optional[int] = OMIT,
        character_limit: typing.Optional[int] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttachmentResponse:
        """
        Attach an entity (assistant, user, model, vector_store, organization) to a rule with configuration.

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

        entity_type : EntityType
            Type of entity to attach

        entity_id : str
            ID of entity to attach

        priority : typing.Optional[int]
            Priority (1-100, default 50)

        character_limit : typing.Optional[int]
            Character limit for rule content (100-50000)

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

        Returns
        -------
        AttachmentResponse
            Entity attached successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_attachments.attach_entity(
                rule_id="rule_id",
                entity_type="assistant",
                entity_id="asst_abc123",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.attach_entity(
            rule_id,
            entity_type=entity_type,
            entity_id=entity_id,
            priority=priority,
            character_limit=character_limit,
            request_options=request_options,
        )
        return _response.data

    async def get_attachment(
        self, rule_id: str, entity_type: str, entity_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AttachmentResponse:
        """
        Get details of a specific attachment by rule, entity type, and entity ID.

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

        entity_type : str

        entity_id : str

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

        Returns
        -------
        AttachmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_attachments.get_attachment(
                rule_id="rule_id",
                entity_type="entity_type",
                entity_id="entity_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_attachment(
            rule_id, entity_type, entity_id, request_options=request_options
        )
        return _response.data

    async def update_attachment(
        self,
        rule_id: str,
        entity_type: str,
        entity_id: str,
        *,
        include_rule_details: typing.Optional[bool] = None,
        priority: typing.Optional[int] = OMIT,
        character_limit: typing.Optional[int] = OMIT,
        is_active: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttachmentResponse:
        """
        Update attachment configuration (priority, character limit, is_active).

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

        entity_type : str

        entity_id : str

        include_rule_details : typing.Optional[bool]
            Include rule summary (name, category) in response

        priority : typing.Optional[int]
            Priority (1-100)

        character_limit : typing.Optional[int]
            Character limit (100-50000)

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

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

        Returns
        -------
        AttachmentResponse
            Attachment updated successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_attachments.update_attachment(
                rule_id="rule_id",
                entity_type="entity_type",
                entity_id="entity_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_attachment(
            rule_id,
            entity_type,
            entity_id,
            include_rule_details=include_rule_details,
            priority=priority,
            character_limit=character_limit,
            is_active=is_active,
            request_options=request_options,
        )
        return _response.data

    async def detach_entity(
        self, rule_id: str, entity_type: str, entity_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AttachmentDeleteResponse:
        """
        Remove an entity attachment from a rule (soft delete).

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

        entity_type : str

        entity_id : str

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

        Returns
        -------
        AttachmentDeleteResponse
            Entity detached successfully

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.rule_attachments.detach_entity(
                rule_id="rule_id",
                entity_type="entity_type",
                entity_id="entity_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.detach_entity(
            rule_id, entity_type, entity_id, request_options=request_options
        )
        return _response.data
