"use strict";async function toggleOTPQuery(e,t){return await db_1.models.twoFactor.update({enabled:t},{where:{userId:e},returning:!0})}Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const error_1=require("@b/utils/error"),db_1=require("@b/db");exports.metadata={summary:"Toggles OTP status",operationId:"toggleOtp",tags:["Auth"],description:"Enables or disables OTP for the user",requiresAuth:!0,logModule:"2FA",logTitle:"Toggle 2FA status",requestBody:{required:!0,content:{"application/json":{schema:{type:"object",properties:{status:{type:"boolean",description:"Status to set for OTP (enabled or disabled)"}},required:["status"]}}}},responses:{200:{description:"OTP status updated successfully",content:{"application/json":{schema:{type:"object",properties:{message:{type:"string",description:"Success message"}}}}}},400:{description:"Invalid request"},401:{description:"Unauthorized"}}};exports.default=async e=>{const{body:t,user:s,ctx:a}=e;try{null==a||a.step("Validating user authentication");if(!s){null==a||a.fail("User not authenticated");throw(0,error_1.createError)({statusCode:401,message:"unauthorized"})}null==a||a.step("Validating status value");if("boolean"!=typeof t.status){null==a||a.fail("Status must be a boolean");throw(0,error_1.createError)({statusCode:400,message:"Status must be a boolean value"})}null==a||a.step((t.status?"Enabling":"Disabling")+" 2FA");const e=await toggleOTPQuery(s.id,t.status);null==a||a.success(`2FA ${t.status?"enabled":"disabled"} successfully`);return e}catch(e){null==a||a.fail(e.message||"Failed to toggle 2FA");throw e}};