# 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.click_up_o_auth_success_response import ClickUpOAuthSuccessResponse
from .raw_client import AsyncRawClickupOauthClient, RawClickupOauthClient


class ClickupOauthClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawClickupOauthClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawClickupOauthClient
        """
        return self._raw_client

    def authorize_click_up(
        self,
        *,
        instance_id: str,
        client_id: typing.Optional[str] = None,
        redirect_url: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Start ClickUp OAuth flow

        Parameters:
        - instance_id: Identifier for the instance requesting authorization
        - client_id: Optional client ID for white labeling
        - redirect_url: Optional URL to redirect to after authorization completes

        Parameters
        ----------
        instance_id : str
            Unique identifier for the client instance requesting authorization

        client_id : typing.Optional[str]
            Client ID for white labeling, if not provided will use default credentials

        redirect_url : typing.Optional[str]
            Optional URL to redirect to after authorization completes

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.clickup_oauth.authorize_click_up(
            instance_id="instance_id",
        )
        """
        _response = self._raw_client.authorize_click_up(
            instance_id=instance_id, client_id=client_id, redirect_url=redirect_url, request_options=request_options
        )
        return _response.data

    def click_up_o_auth_callback(
        self,
        *,
        code: typing.Optional[str] = None,
        state: typing.Optional[str] = None,
        error: typing.Optional[str] = None,
        error_description: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClickUpOAuthSuccessResponse:
        """
        Handles the callback from ClickUp OAuth authorization.

        Parameters
        ----------
        code : typing.Optional[str]
            Authorization code returned by ClickUp

        state : typing.Optional[str]
            State parameter containing encoded authorization data

        error : typing.Optional[str]
            Error code returned by ClickUp, if any

        error_description : typing.Optional[str]
            Detailed error description from ClickUp, if any

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

        Returns
        -------
        ClickUpOAuthSuccessResponse
            Successful Response

        Examples
        --------
        from klavis import Klavis

        client = Klavis(
            api_key="YOUR_API_KEY",
        )
        client.clickup_oauth.click_up_o_auth_callback()
        """
        _response = self._raw_client.click_up_o_auth_callback(
            code=code, state=state, error=error, error_description=error_description, request_options=request_options
        )
        return _response.data


class AsyncClickupOauthClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawClickupOauthClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawClickupOauthClient
        """
        return self._raw_client

    async def authorize_click_up(
        self,
        *,
        instance_id: str,
        client_id: typing.Optional[str] = None,
        redirect_url: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Start ClickUp OAuth flow

        Parameters:
        - instance_id: Identifier for the instance requesting authorization
        - client_id: Optional client ID for white labeling
        - redirect_url: Optional URL to redirect to after authorization completes

        Parameters
        ----------
        instance_id : str
            Unique identifier for the client instance requesting authorization

        client_id : typing.Optional[str]
            Client ID for white labeling, if not provided will use default credentials

        redirect_url : typing.Optional[str]
            Optional URL to redirect to after authorization completes

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.clickup_oauth.authorize_click_up(
                instance_id="instance_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.authorize_click_up(
            instance_id=instance_id, client_id=client_id, redirect_url=redirect_url, request_options=request_options
        )
        return _response.data

    async def click_up_o_auth_callback(
        self,
        *,
        code: typing.Optional[str] = None,
        state: typing.Optional[str] = None,
        error: typing.Optional[str] = None,
        error_description: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ClickUpOAuthSuccessResponse:
        """
        Handles the callback from ClickUp OAuth authorization.

        Parameters
        ----------
        code : typing.Optional[str]
            Authorization code returned by ClickUp

        state : typing.Optional[str]
            State parameter containing encoded authorization data

        error : typing.Optional[str]
            Error code returned by ClickUp, if any

        error_description : typing.Optional[str]
            Detailed error description from ClickUp, if any

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

        Returns
        -------
        ClickUpOAuthSuccessResponse
            Successful Response

        Examples
        --------
        import asyncio

        from klavis import AsyncKlavis

        client = AsyncKlavis(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.clickup_oauth.click_up_o_auth_callback()


        asyncio.run(main())
        """
        _response = await self._raw_client.click_up_o_auth_callback(
            code=code, state=state, error=error, error_description=error_description, request_options=request_options
        )
        return _response.data
