# 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.create_flowplate_key_response import CreateFlowplateKeyResponse
from ..types.flowplate_key_action_response import FlowplateKeyActionResponse
from ..types.refresh_flowplate_key_response import RefreshFlowplateKeyResponse
from .raw_client import AsyncRawFlowplateIntegrationClient, RawFlowplateIntegrationClient

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


class FlowplateIntegrationClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawFlowplateIntegrationClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawFlowplateIntegrationClient
        """
        return self._raw_client

    def create_flowplate_api_key(
        self,
        *,
        flowplate_master_key: str,
        user_id: str,
        organization_id: str,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateFlowplateKeyResponse:
        """
        Create a hidden API key for a Flowplate user+org.

        Called by Flowplate backend during user login.
        Requires X-Flowplate-Master-Key header.

        The raw API key is returned ONCE and must be stored securely by Flowplate.

        Parameters
        ----------
        flowplate_master_key : str
            Flowplate master API key

        user_id : str
            Aitronos user ID

        organization_id : str
            Organization ID

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Optional metadata for the key

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

        Returns
        -------
        CreateFlowplateKeyResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.flowplate_integration.create_flowplate_api_key(
            flowplate_master_key="x-flowplate-master-key",
            user_id="user_id",
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.create_flowplate_api_key(
            flowplate_master_key=flowplate_master_key,
            user_id=user_id,
            organization_id=organization_id,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def refresh_flowplate_api_key(
        self,
        user_id: str,
        org_id: str,
        *,
        flowplate_master_key: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RefreshFlowplateKeyResponse:
        """
        Rotate a user's Flowplate API key.

        Deletes the old key and creates a new one with the same settings.
        Requires X-Flowplate-Master-Key header.

        The new raw API key is returned ONCE and must be stored securely by Flowplate.

        Parameters
        ----------
        user_id : str

        org_id : str

        flowplate_master_key : str
            Flowplate master API key

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

        Returns
        -------
        RefreshFlowplateKeyResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.flowplate_integration.refresh_flowplate_api_key(
            user_id="user_id",
            org_id="org_id",
            flowplate_master_key="x-flowplate-master-key",
        )
        """
        _response = self._raw_client.refresh_flowplate_api_key(
            user_id, org_id, flowplate_master_key=flowplate_master_key, request_options=request_options
        )
        return _response.data

    def revoke_flowplate_api_key(
        self,
        user_id: str,
        org_id: str,
        *,
        flowplate_master_key: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FlowplateKeyActionResponse:
        """
        Revoke a user's Flowplate API key.

        Soft-deletes the key so it can no longer be used.
        Requires X-Flowplate-Master-Key header.

        Parameters
        ----------
        user_id : str

        org_id : str

        flowplate_master_key : str
            Flowplate master API key

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

        Returns
        -------
        FlowplateKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.flowplate_integration.revoke_flowplate_api_key(
            user_id="user_id",
            org_id="org_id",
            flowplate_master_key="x-flowplate-master-key",
        )
        """
        _response = self._raw_client.revoke_flowplate_api_key(
            user_id, org_id, flowplate_master_key=flowplate_master_key, request_options=request_options
        )
        return _response.data

    def revoke_all_user_keys(
        self, user_id: str, *, flowplate_master_key: str, request_options: typing.Optional[RequestOptions] = None
    ) -> FlowplateKeyActionResponse:
        """
        Revoke all Flowplate API keys for a user.

        Called when a user account is deactivated.
        Requires X-Flowplate-Master-Key header.

        Parameters
        ----------
        user_id : str

        flowplate_master_key : str
            Flowplate master API key

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

        Returns
        -------
        FlowplateKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.flowplate_integration.revoke_all_user_keys(
            user_id="user_id",
            flowplate_master_key="x-flowplate-master-key",
        )
        """
        _response = self._raw_client.revoke_all_user_keys(
            user_id, flowplate_master_key=flowplate_master_key, request_options=request_options
        )
        return _response.data


class AsyncFlowplateIntegrationClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawFlowplateIntegrationClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawFlowplateIntegrationClient
        """
        return self._raw_client

    async def create_flowplate_api_key(
        self,
        *,
        flowplate_master_key: str,
        user_id: str,
        organization_id: str,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateFlowplateKeyResponse:
        """
        Create a hidden API key for a Flowplate user+org.

        Called by Flowplate backend during user login.
        Requires X-Flowplate-Master-Key header.

        The raw API key is returned ONCE and must be stored securely by Flowplate.

        Parameters
        ----------
        flowplate_master_key : str
            Flowplate master API key

        user_id : str
            Aitronos user ID

        organization_id : str
            Organization ID

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Optional metadata for the key

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

        Returns
        -------
        CreateFlowplateKeyResponse
            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.flowplate_integration.create_flowplate_api_key(
                flowplate_master_key="x-flowplate-master-key",
                user_id="user_id",
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_flowplate_api_key(
            flowplate_master_key=flowplate_master_key,
            user_id=user_id,
            organization_id=organization_id,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def refresh_flowplate_api_key(
        self,
        user_id: str,
        org_id: str,
        *,
        flowplate_master_key: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> RefreshFlowplateKeyResponse:
        """
        Rotate a user's Flowplate API key.

        Deletes the old key and creates a new one with the same settings.
        Requires X-Flowplate-Master-Key header.

        The new raw API key is returned ONCE and must be stored securely by Flowplate.

        Parameters
        ----------
        user_id : str

        org_id : str

        flowplate_master_key : str
            Flowplate master API key

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

        Returns
        -------
        RefreshFlowplateKeyResponse
            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.flowplate_integration.refresh_flowplate_api_key(
                user_id="user_id",
                org_id="org_id",
                flowplate_master_key="x-flowplate-master-key",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.refresh_flowplate_api_key(
            user_id, org_id, flowplate_master_key=flowplate_master_key, request_options=request_options
        )
        return _response.data

    async def revoke_flowplate_api_key(
        self,
        user_id: str,
        org_id: str,
        *,
        flowplate_master_key: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> FlowplateKeyActionResponse:
        """
        Revoke a user's Flowplate API key.

        Soft-deletes the key so it can no longer be used.
        Requires X-Flowplate-Master-Key header.

        Parameters
        ----------
        user_id : str

        org_id : str

        flowplate_master_key : str
            Flowplate master API key

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

        Returns
        -------
        FlowplateKeyActionResponse
            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.flowplate_integration.revoke_flowplate_api_key(
                user_id="user_id",
                org_id="org_id",
                flowplate_master_key="x-flowplate-master-key",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.revoke_flowplate_api_key(
            user_id, org_id, flowplate_master_key=flowplate_master_key, request_options=request_options
        )
        return _response.data

    async def revoke_all_user_keys(
        self, user_id: str, *, flowplate_master_key: str, request_options: typing.Optional[RequestOptions] = None
    ) -> FlowplateKeyActionResponse:
        """
        Revoke all Flowplate API keys for a user.

        Called when a user account is deactivated.
        Requires X-Flowplate-Master-Key header.

        Parameters
        ----------
        user_id : str

        flowplate_master_key : str
            Flowplate master API key

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

        Returns
        -------
        FlowplateKeyActionResponse
            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.flowplate_integration.revoke_all_user_keys(
                user_id="user_id",
                flowplate_master_key="x-flowplate-master-key",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.revoke_all_user_keys(
            user_id, flowplate_master_key=flowplate_master_key, request_options=request_options
        )
        return _response.data
