# 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.apply_mode import ApplyMode
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
from .raw_client import AsyncRawRuleOperationsClient, RawRuleOperationsClient

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


class RuleOperationsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRuleOperationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRuleOperationsClient
        """
        return self._raw_client

    def update_rule(
        self,
        org_id: str,
        rule_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        content: typing.Optional[str] = OMIT,
        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,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RuleDetailResponse:
        """
        Update an existing rule. Requires edit or owner access.

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

        rule_id : str

        name : typing.Optional[str]

        content : typing.Optional[str]

        description : typing.Optional[str]

        category : typing.Optional[RuleCategory]

        rule_type : typing.Optional[RuleType]

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

        apply_mode : typing.Optional[ApplyMode]

        is_public : typing.Optional[bool]

        is_active : typing.Optional[bool]

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

        Returns
        -------
        RuleDetailResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_operations.update_rule(
            org_id="org_id",
            rule_id="rule_id",
        )
        """
        _response = self._raw_client.update_rule(
            org_id,
            rule_id,
            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,
            request_options=request_options,
        )
        return _response.data

    def delete_rule(
        self,
        org_id: str,
        rule_id: str,
        *,
        force: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Soft delete a rule. Requires owner access.

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

        rule_id : str

        force : typing.Optional[bool]
            Force delete even if rule has active attachments

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

        Returns
        -------
        None

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_operations.delete_rule(
            org_id="org_id",
            rule_id="rule_id",
        )
        """
        _response = self._raw_client.delete_rule(org_id, rule_id, force=force, request_options=request_options)
        return _response.data

    def list_public_rules(
        self,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        category: typing.Optional[RuleCategory] = None,
        rule_type: typing.Optional[RuleType] = None,
        scope: typing.Optional[RuleScope] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RuleListPaginatedResponse:
        """
        List all public rules from all organizations.

        Parameters
        ----------
        skip : typing.Optional[int]

        limit : typing.Optional[int]

        category : typing.Optional[RuleCategory]

        rule_type : typing.Optional[RuleType]

        scope : typing.Optional[RuleScope]

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

        Returns
        -------
        RuleListPaginatedResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_operations.list_public_rules()
        """
        _response = self._raw_client.list_public_rules(
            skip=skip, limit=limit, category=category, rule_type=rule_type, scope=scope, request_options=request_options
        )
        return _response.data

    def duplicate_rule(
        self, org_id: str, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RuleDetailResponse:
        """
        Create a copy of an existing rule with a new ID and name suffix.

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

        rule_id : str

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

        Returns
        -------
        RuleDetailResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.rule_operations.duplicate_rule(
            org_id="org_id",
            rule_id="rule_id",
        )
        """
        _response = self._raw_client.duplicate_rule(org_id, rule_id, request_options=request_options)
        return _response.data


class AsyncRuleOperationsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRuleOperationsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRuleOperationsClient
        """
        return self._raw_client

    async def update_rule(
        self,
        org_id: str,
        rule_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        content: typing.Optional[str] = OMIT,
        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,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RuleDetailResponse:
        """
        Update an existing rule. Requires edit or owner access.

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

        rule_id : str

        name : typing.Optional[str]

        content : typing.Optional[str]

        description : typing.Optional[str]

        category : typing.Optional[RuleCategory]

        rule_type : typing.Optional[RuleType]

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

        apply_mode : typing.Optional[ApplyMode]

        is_public : typing.Optional[bool]

        is_active : typing.Optional[bool]

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

        Returns
        -------
        RuleDetailResponse
            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_operations.update_rule(
                org_id="org_id",
                rule_id="rule_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_rule(
            org_id,
            rule_id,
            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,
            request_options=request_options,
        )
        return _response.data

    async def delete_rule(
        self,
        org_id: str,
        rule_id: str,
        *,
        force: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Soft delete a rule. Requires owner access.

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

        rule_id : str

        force : typing.Optional[bool]
            Force delete even if rule has active attachments

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

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


        async def main() -> None:
            await client.rule_operations.delete_rule(
                org_id="org_id",
                rule_id="rule_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_rule(org_id, rule_id, force=force, request_options=request_options)
        return _response.data

    async def list_public_rules(
        self,
        *,
        skip: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        category: typing.Optional[RuleCategory] = None,
        rule_type: typing.Optional[RuleType] = None,
        scope: typing.Optional[RuleScope] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RuleListPaginatedResponse:
        """
        List all public rules from all organizations.

        Parameters
        ----------
        skip : typing.Optional[int]

        limit : typing.Optional[int]

        category : typing.Optional[RuleCategory]

        rule_type : typing.Optional[RuleType]

        scope : typing.Optional[RuleScope]

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

        Returns
        -------
        RuleListPaginatedResponse
            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_operations.list_public_rules()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_public_rules(
            skip=skip, limit=limit, category=category, rule_type=rule_type, scope=scope, request_options=request_options
        )
        return _response.data

    async def duplicate_rule(
        self, org_id: str, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RuleDetailResponse:
        """
        Create a copy of an existing rule with a new ID and name suffix.

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

        rule_id : str

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

        Returns
        -------
        RuleDetailResponse
            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_operations.duplicate_rule(
                org_id="org_id",
                rule_id="rule_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.duplicate_rule(org_id, rule_id, request_options=request_options)
        return _response.data
