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

class HeadlessB2BTOTPsClient {
    _networkClient;
    _subscriptionService;
    dfpProtectedAuth;
    authenticate;
    constructor(_networkClient, _subscriptionService, dfpProtectedAuth){
        this._networkClient = _networkClient;
        this._subscriptionService = _subscriptionService;
        this.dfpProtectedAuth = dfpProtectedAuth;
        this.authenticate = this._subscriptionService.withUpdateSession(async (data)=>{
            validateInDev('stytch.totp.authenticate', data, {
                organization_id: 'string',
                member_id: 'string',
                code: 'string',
                session_duration_minutes: 'number',
                set_mfa_enrollment: 'optionalString',
                set_default_mfa: 'optionalBoolean'
            });
            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/totp/authenticate',
                body: requestBody,
                method: 'POST',
                retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
            });
        });
    }
    async create(data) {
        validateInDev('stytch.totp.create', data, {
            organization_id: 'string',
            member_id: 'string',
            expiration_minutes: 'optionalNumber'
        });
        const { dfp_telemetry_id, captcha_token } = await this.dfpProtectedAuth.getDFPTelemetryIDAndCaptcha();
        const response = await this._networkClient.retriableFetchSDK({
            url: '/b2b/totp',
            body: {
                ...data,
                dfp_telemetry_id,
                captcha_token,
                intermediate_session_token: await this._subscriptionService.getIntermediateSessionToken() || undefined
            },
            method: 'POST',
            retryCallback: this.dfpProtectedAuth.retryWithCaptchaAndDFP
        });
        if (response.member_id === this._subscriptionService.getMember()?.member_id) {
            this._subscriptionService.updateMember(response.member);
        }
        return response;
    }
}

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