# 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.retention_rule_page_public import RetentionRulePagePublic
from ..types.retention_rule_public import RetentionRulePublic
from .raw_client import AsyncRawRetentionRulesClient, RawRetentionRulesClient
from .types.retention_rule_write_retention import RetentionRuleWriteRetention

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


class RetentionRulesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawRetentionRulesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawRetentionRulesClient
        """
        return self._raw_client

    def find_retention_rules(
        self,
        *,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        include_inactive: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RetentionRulePagePublic:
        """
        List retention rules for the caller's workspace. Defaults to active only.

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

        size : typing.Optional[int]

        include_inactive : typing.Optional[bool]

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

        Returns
        -------
        RetentionRulePagePublic
            Retention rules page

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.retention_rules.find_retention_rules()
        """
        _response = self._raw_client.find_retention_rules(
            page=page, size=size, include_inactive=include_inactive, request_options=request_options
        )
        return _response.data

    def create_retention_rule(
        self,
        *,
        retention: RetentionRuleWriteRetention,
        project_id: typing.Optional[str] = OMIT,
        organization_level: typing.Optional[bool] = OMIT,
        apply_to_past: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RetentionRulePublic:
        """
        Create a new retention rule. Auto-deactivates any existing active rule for the same scope.

        Parameters
        ----------
        retention : RetentionRuleWriteRetention

        project_id : typing.Optional[str]

        organization_level : typing.Optional[bool]
            Set to true to create an organization-level rule

        apply_to_past : typing.Optional[bool]

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

        Returns
        -------
        RetentionRulePublic
            Created

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.retention_rules.create_retention_rule(retention="short_14d", )
        """
        _response = self._raw_client.create_retention_rule(
            retention=retention,
            project_id=project_id,
            organization_level=organization_level,
            apply_to_past=apply_to_past,
            request_options=request_options,
        )
        return _response.data

    def get_retention_rule_by_id(
        self, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RetentionRulePublic:
        """
        Get a specific retention rule by id

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

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

        Returns
        -------
        RetentionRulePublic
            Retention rule

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.retention_rules.get_retention_rule_by_id(rule_id='ruleId', )
        """
        _response = self._raw_client.get_retention_rule_by_id(rule_id, request_options=request_options)
        return _response.data

    def deactivate_retention_rule(
        self, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Soft-deactivate a retention rule (sets enabled=false). Rules are never hard-deleted for audit trail.

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

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import OpikApi
        client = OpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        client.retention_rules.deactivate_retention_rule(rule_id='ruleId', )
        """
        _response = self._raw_client.deactivate_retention_rule(rule_id, request_options=request_options)
        return _response.data


class AsyncRetentionRulesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawRetentionRulesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawRetentionRulesClient
        """
        return self._raw_client

    async def find_retention_rules(
        self,
        *,
        page: typing.Optional[int] = None,
        size: typing.Optional[int] = None,
        include_inactive: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RetentionRulePagePublic:
        """
        List retention rules for the caller's workspace. Defaults to active only.

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

        size : typing.Optional[int]

        include_inactive : typing.Optional[bool]

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

        Returns
        -------
        RetentionRulePagePublic
            Retention rules page

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.retention_rules.find_retention_rules()
        asyncio.run(main())
        """
        _response = await self._raw_client.find_retention_rules(
            page=page, size=size, include_inactive=include_inactive, request_options=request_options
        )
        return _response.data

    async def create_retention_rule(
        self,
        *,
        retention: RetentionRuleWriteRetention,
        project_id: typing.Optional[str] = OMIT,
        organization_level: typing.Optional[bool] = OMIT,
        apply_to_past: typing.Optional[bool] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RetentionRulePublic:
        """
        Create a new retention rule. Auto-deactivates any existing active rule for the same scope.

        Parameters
        ----------
        retention : RetentionRuleWriteRetention

        project_id : typing.Optional[str]

        organization_level : typing.Optional[bool]
            Set to true to create an organization-level rule

        apply_to_past : typing.Optional[bool]

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

        Returns
        -------
        RetentionRulePublic
            Created

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.retention_rules.create_retention_rule(retention="short_14d", )
        asyncio.run(main())
        """
        _response = await self._raw_client.create_retention_rule(
            retention=retention,
            project_id=project_id,
            organization_level=organization_level,
            apply_to_past=apply_to_past,
            request_options=request_options,
        )
        return _response.data

    async def get_retention_rule_by_id(
        self, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RetentionRulePublic:
        """
        Get a specific retention rule by id

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

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

        Returns
        -------
        RetentionRulePublic
            Retention rule

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.retention_rules.get_retention_rule_by_id(rule_id='ruleId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.get_retention_rule_by_id(rule_id, request_options=request_options)
        return _response.data

    async def deactivate_retention_rule(
        self, rule_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Soft-deactivate a retention rule (sets enabled=false). Rules are never hard-deleted for audit trail.

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

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

        Returns
        -------
        None

        Examples
        --------
        from Opik import AsyncOpikApi
        import asyncio
        client = AsyncOpikApi(api_key="YOUR_API_KEY", workspace_name="YOUR_WORKSPACE_NAME", )
        async def main() -> None:
            await client.retention_rules.deactivate_retention_rule(rule_id='ruleId', )
        asyncio.run(main())
        """
        _response = await self._raw_client.deactivate_retention_rule(rule_id, request_options=request_options)
        return _response.data
