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

from __future__ import annotations

from typing import Any, Dict, Optional

from stytch.b2b.models.otp_sms import (
    AuthenticateResponse,
    SendRequestLocale,
    SendResponse,
)
from stytch.core.api_base import ApiBase
from stytch.core.http.client import AsyncClient, SyncClient


class Sms:
    def __init__(
        self,
        api_base: ApiBase,
        sync_client: SyncClient,
        async_client: AsyncClient,
    ) -> None:
        self.api_base = api_base
        self.sync_client = sync_client
        self.async_client = async_client

    def send(
        self,
        organization_id: str,
        member_id: str,
        phone_number: Optional[str] = None,
        locale: Optional[SendRequestLocale] = None,
    ) -> SendResponse:
        data: Dict[str, Any] = {
            "organization_id": organization_id,
            "member_id": member_id,
        }
        if phone_number is not None:
            data["phone_number"] = phone_number
        if locale is not None:
            data["locale"] = locale.value

        url = self.api_base.url_for("/v1/b2b/otps/sms/send", data)
        res = self.sync_client.post(url, data)
        return SendResponse.from_json(res.response.status_code, res.json)

    async def send_async(
        self,
        organization_id: str,
        member_id: str,
        phone_number: Optional[str] = None,
        locale: Optional[SendRequestLocale] = None,
    ) -> SendResponse:
        data: Dict[str, Any] = {
            "organization_id": organization_id,
            "member_id": member_id,
        }
        if phone_number is not None:
            data["phone_number"] = phone_number
        if locale is not None:
            data["locale"] = locale.value

        url = self.api_base.url_for("/v1/b2b/otps/sms/send", data)
        res = await self.async_client.post(url, data)
        return SendResponse.from_json(res.response.status, res.json)

    def authenticate(
        self,
        organization_id: str,
        member_id: str,
        code: str,
        intermediate_session_token: Optional[str] = None,
        session_token: Optional[str] = None,
        session_jwt: Optional[str] = None,
        session_duration_minutes: Optional[int] = None,
        session_custom_claims: Optional[Dict[str, Any]] = None,
        set_mfa_enrollment: Optional[str] = None,
    ) -> AuthenticateResponse:
        data: Dict[str, Any] = {
            "organization_id": organization_id,
            "member_id": member_id,
            "code": code,
        }
        if intermediate_session_token is not None:
            data["intermediate_session_token"] = intermediate_session_token
        if session_token is not None:
            data["session_token"] = session_token
        if session_jwt is not None:
            data["session_jwt"] = session_jwt
        if session_duration_minutes is not None:
            data["session_duration_minutes"] = session_duration_minutes
        if session_custom_claims is not None:
            data["session_custom_claims"] = session_custom_claims
        if set_mfa_enrollment is not None:
            data["set_mfa_enrollment"] = set_mfa_enrollment

        url = self.api_base.url_for("/v1/b2b/otps/sms/authenticate", data)
        res = self.sync_client.post(url, data)
        return AuthenticateResponse.from_json(res.response.status_code, res.json)

    async def authenticate_async(
        self,
        organization_id: str,
        member_id: str,
        code: str,
        intermediate_session_token: Optional[str] = None,
        session_token: Optional[str] = None,
        session_jwt: Optional[str] = None,
        session_duration_minutes: Optional[int] = None,
        session_custom_claims: Optional[Dict[str, Any]] = None,
        set_mfa_enrollment: Optional[str] = None,
    ) -> AuthenticateResponse:
        data: Dict[str, Any] = {
            "organization_id": organization_id,
            "member_id": member_id,
            "code": code,
        }
        if intermediate_session_token is not None:
            data["intermediate_session_token"] = intermediate_session_token
        if session_token is not None:
            data["session_token"] = session_token
        if session_jwt is not None:
            data["session_jwt"] = session_jwt
        if session_duration_minutes is not None:
            data["session_duration_minutes"] = session_duration_minutes
        if session_custom_claims is not None:
            data["session_custom_claims"] = session_custom_claims
        if set_mfa_enrollment is not None:
            data["set_mfa_enrollment"] = set_mfa_enrollment

        url = self.api_base.url_for("/v1/b2b/otps/sms/authenticate", data)
        res = await self.async_client.post(url, data)
        return AuthenticateResponse.from_json(res.response.status, res.json)
