"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const error_1=require("@b/utils/error"),notification_1=require("@b/services/notification");exports.metadata={summary:"Unsubscribe from push notifications",description:"Remove a push notification subscription or token for the current user",operationId:"unsubscribeFromPush",tags:["User","Push Notifications"],requiresAuth:!0,requestBody:{required:!0,content:{"application/json":{schema:{type:"object",properties:{deviceId:{type:"string",description:"Device ID to unsubscribe"},endpoint:{type:"string",description:"Web Push endpoint to unsubscribe (alternative to deviceId)"},token:{type:"string",description:"FCM token to unsubscribe (alternative to deviceId)"}}}}}},responses:{200:{description:"Unsubscribed successfully",content:{"application/json":{schema:{type:"object",properties:{success:{type:"boolean"},message:{type:"string"}}}}}},401:{description:"Unauthorized"}}};exports.default=async e=>{const{user:t,body:s}=e;if(!(null==t?void 0:t.id))throw(0,error_1.createError)({statusCode:401,message:"User not authenticated"});const{deviceId:o,endpoint:i,token:r}=s,n=o||i||r;if(!n)throw(0,error_1.createError)({statusCode:400,message:"Please provide deviceId, endpoint, or token to unsubscribe"});const c=notification_1.notificationService.getChannel("PUSH")||new notification_1.PushChannel;return await c.removeDeviceToken(t.id,n)?{success:!0,message:"Unsubscribed from push notifications successfully"}:{success:!1,message:"Subscription not found or already removed"}};