# !!!
# WARNING: This file is autogenerated
# Only modify code within MANUAL() sections
# or your changes may be overwritten later!
# !!!


from typing import Optional

import jwt

from stytch.b2b.api.discovery import Discovery
from stytch.b2b.api.magic_links import MagicLinks
from stytch.b2b.api.oauth import OAuth
from stytch.b2b.api.organizations import Organizations
from stytch.b2b.api.otp import OTPs
from stytch.b2b.api.passwords import Passwords
from stytch.b2b.api.sessions import Sessions
from stytch.b2b.api.sso import SSO
from stytch.consumer.api.m2m import M2M
from stytch.core.client_base import ClientBase


class Client(ClientBase):
    """
    Stytch API Python client.

    Learn more at https://stytch.com/docs
    """

    def __init__(
        self,
        project_id: str,
        secret: str,
        environment: Optional[str] = None,
        suppress_warnings: bool = False,
    ):
        super().__init__(project_id, secret, environment, suppress_warnings)

        self.discovery = Discovery(self.api_base, self.sync_client, self.async_client)
        self.m2m = M2M(
            self.api_base,
            self.sync_client,
            self.async_client,
            self.jwks_client,
            project_id,
        )
        self.magic_links = MagicLinks(
            self.api_base, self.sync_client, self.async_client
        )
        self.oauth = OAuth(self.api_base, self.sync_client, self.async_client)
        self.otps = OTPs(self.api_base, self.sync_client, self.async_client)
        self.organizations = Organizations(
            self.api_base, self.sync_client, self.async_client
        )
        self.passwords = Passwords(self.api_base, self.sync_client, self.async_client)
        self.sso = SSO(self.api_base, self.sync_client, self.async_client)
        self.sessions = Sessions(
            self.api_base,
            self.sync_client,
            self.async_client,
            self.jwks_client,
            project_id,
        )

    def get_jwks_client(self, project_id: str) -> jwt.PyJWKClient:
        data = {"project_id": project_id}
        url = self.api_base.url_for("/v1/b2b/sessions/jwks/{project_id}", data)
        return jwt.PyJWKClient(url)
