import { validateInDev } from '../../utils/dev.mjs';

class HeadlessB2BOTPsClient {
    _networkClient;
    _subscriptionService;
    dfpProtectedAuth;
    sms;
    email;
    constructor(_networkClient, _subscriptionService, dfpProtectedAuth){
        this._networkClient = _networkClient;
        this._subscriptionService = _subscriptionService;
        this.dfpProtectedAuth = dfpProtectedAuth;
        this.sms = {
            send: async (data)=>{
                validateInDev('stytch.otps.sms.send', data, {
                    organization_id: 'string',
                    member_id: 'string',
                    mfa_phone_number: 'optionalString',
                    locale: 'optionalString'
                });
                const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
                return this._networkClient.retriableFetchSDK({
                    url: '/b2b/otps/sms/send',
                    body: {
                        ...data,
                        dfp_telemetry_id,
                        captcha_token,
                        intermediate_session_token: this._subscriptionService.getIntermediateSessionToken() || undefined
                    },
                    method: 'POST',
                    retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
                });
            },
            authenticate: this._subscriptionService.withUpdateSession(async (data)=>{
                validateInDev('stytch.otps.sms.authenticate', data, {
                    session_duration_minutes: 'number',
                    organization_id: 'string',
                    member_id: 'string',
                    code: 'string',
                    set_mfa_enrollment: 'optionalString'
                });
                const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
                const requestBody = {
                    ...data,
                    dfp_telemetry_id,
                    captcha_token,
                    intermediate_session_token: this._subscriptionService.getIntermediateSessionToken() || undefined
                };
                return this._networkClient.retriableFetchSDK({
                    url: '/b2b/otps/sms/authenticate',
                    body: requestBody,
                    method: 'POST',
                    retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
                });
            })
        };
        this.email = {
            loginOrSignup: async (data)=>{
                validateInDev('stytch.otps.email.loginOrSignup', data, {
                    organization_id: 'string',
                    email_address: 'string',
                    login_template_id: 'optionalString',
                    signup_template_id: 'optionalString',
                    locale: 'optionalString',
                    login_expiration_minutes: 'optionalNumber',
                    signup_expiration_minutes: 'optionalNumber'
                });
                const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
                return this._networkClient.retriableFetchSDK({
                    url: '/b2b/otps/email/login_or_signup',
                    body: {
                        ...data,
                        dfp_telemetry_id,
                        captcha_token
                    },
                    method: 'POST',
                    retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
                });
            },
            authenticate: this._subscriptionService.withUpdateSession(async (data)=>{
                validateInDev('stytch.otps.email.authenticate', data, {
                    code: 'string',
                    email_address: 'string',
                    organization_id: 'string',
                    session_duration_minutes: 'number',
                    locale: 'optionalString'
                });
                const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
                return this._networkClient.retriableFetchSDK({
                    url: '/b2b/otps/email/authenticate',
                    body: {
                        ...data,
                        intermediate_session_token: this._subscriptionService.getIntermediateSessionToken() || undefined,
                        dfp_telemetry_id,
                        captcha_token
                    },
                    method: 'POST',
                    retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
                });
            }),
            discovery: {
                send: async (data)=>{
                    validateInDev('stytch.otps.email.discovery.send', data, {
                        email_address: 'string',
                        login_template_id: 'optionalString',
                        locale: 'optionalString',
                        discovery_expiration_minutes: 'optionalNumber'
                    });
                    const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
                    const requestBody = {
                        ...data,
                        dfp_telemetry_id,
                        captcha_token
                    };
                    return this._networkClient.retriableFetchSDK({
                        url: '/b2b/otps/email/discovery/send',
                        body: requestBody,
                        method: 'POST',
                        retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
                    });
                },
                authenticate: this._subscriptionService.withUpdateSession(async (data)=>{
                    validateInDev('stytch.otps.email.discovery.authenticate', data, {
                        code: 'string',
                        email_address: 'string'
                    });
                    const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
                    const requestBody = {
                        dfp_telemetry_id,
                        captcha_token,
                        ...data
                    };
                    return this._networkClient.retriableFetchSDK({
                        url: '/b2b/otps/email/discovery/authenticate',
                        body: requestBody,
                        method: 'POST',
                        retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
                    });
                })
            }
        };
    }
}

export { HeadlessB2BOTPsClient };
//# sourceMappingURL=HeadlessB2BOTPsClient.mjs.map
