"use strict";async function toggleOTPQuery(e,t){await db_1.models.twoFactor.update({enabled:t},{where:{userId:e}});const r=await db_1.models.twoFactor.findOne({where:{userId:e}});if(!r)throw(0,error_1.createError)({statusCode:404,message:"TwoFactor record not found"});return r.get({plain:!0})}Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;exports.toggleOTPQuery=toggleOTPQuery;const error_1=require("@b/utils/error"),db_1=require("@b/db"),query_1=require("@b/utils/query");exports.metadata={summary:"Toggles the OTP feature for the user account",operationId:"toggleOTP",description:"Toggles the OTP feature for the user account",tags:["Profile"],requiresAuth:!0,logModule:"USER",logTitle:"Toggle OTP status",requestBody:{required:!0,content:{"application/json":{schema:{type:"object",properties:{status:{type:"boolean",description:"Status of the OTP feature"}},required:["status"]}}}},responses:{200:{description:"OTP feature toggled successfully",content:{"application/json":{schema:{type:"object",properties:{status:{type:"boolean",description:"Indicates if the request was successful"},statusCode:{type:"number",description:"HTTP status code",example:200},data:{type:"object",properties:{message:{type:"string",description:"Message indicating the status of the OTP feature"}}}}}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("User"),500:query_1.serverErrorResponse}};exports.default=async e=>{const{user:t,body:r,ctx:s}=e;if(!(null==t?void 0:t.id)){null==s||s.fail("User not authenticated");throw(0,error_1.createError)({statusCode:401,message:"Unauthorized"})}const{status:o}=r;null==s||s.step((o?"Enabling":"Disabling")+" OTP feature");await toggleOTPQuery(t.id,o);null==s||s.success("OTP feature "+(o?"enabled":"disabled"));return{message:"OTP feature has been "+(o?"enabled":"disabled")}};