# 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 .raw_client import AsyncRawShopifyOauthClient, RawShopifyOauthClient


class ShopifyOauthClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawShopifyOauthClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawShopifyOauthClient
        """
        return self._raw_client

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

        Parameters:
        - instance_id: Identifier for the instance requesting authorization
        - shop: Shopify shop domain (e.g., mystore.myshopify.com)
        - client_id: Optional client ID for white labeling
        - scope: Optional scopes to request (comma-separated)
        - redirect_url: Optional URL to redirect to after authorization completes

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

        shop : str
            Shopify shop domain (e.g., mystore.myshopify.com)

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

        scope : typing.Optional[str]
            Optional OAuth scopes to request (comma-separated string)

        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.shopify_oauth.authorize_shopify(
            instance_id="instance_id",
            shop="shop",
        )
        """
        _response = self._raw_client.authorize_shopify(
            instance_id=instance_id,
            shop=shop,
            client_id=client_id,
            scope=scope,
            redirect_url=redirect_url,
            request_options=request_options,
        )
        return _response.data


class AsyncShopifyOauthClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawShopifyOauthClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawShopifyOauthClient
        """
        return self._raw_client

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

        Parameters:
        - instance_id: Identifier for the instance requesting authorization
        - shop: Shopify shop domain (e.g., mystore.myshopify.com)
        - client_id: Optional client ID for white labeling
        - scope: Optional scopes to request (comma-separated)
        - redirect_url: Optional URL to redirect to after authorization completes

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

        shop : str
            Shopify shop domain (e.g., mystore.myshopify.com)

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

        scope : typing.Optional[str]
            Optional OAuth scopes to request (comma-separated string)

        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.shopify_oauth.authorize_shopify(
                instance_id="instance_id",
                shop="shop",
            )


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