"use strict";async function processExpiredUserBlocks(){const e="processExpiredUserBlocks",s=Date.now();try{(0,broadcast_1.broadcastStatus)(e,"running");(0,broadcast_1.broadcastLog)(e,"Starting expired user blocks processing");const r=await db_1.models.userBlock.findAll({where:{isTemporary:!0,isActive:!0,blockedUntil:{[sequelize_1.Op.lt]:new Date}},include:[{model:db_1.models.user,as:"user",attributes:["id","status","firstName","lastName","email"]}]});(0,broadcast_1.broadcastLog)(e,`Found ${r.length} expired temporary blocks`);for(const s of r)try{await s.update({isActive:!1});if(!await db_1.models.userBlock.findOne({where:{userId:s.userId,isActive:!0,id:{[sequelize_1.Op.ne]:s.id}}})&&s.user){await s.user.update({status:"ACTIVE"});(0,broadcast_1.broadcastLog)(e,`Auto-unblocked user ${s.user.firstName} ${s.user.lastName} (${s.user.email})`,"success")}}catch(r){console_1.logger.error("CRON",`Error processing expired block ${s.id}`,r);(0,broadcast_1.broadcastLog)(e,`Error processing expired block ${s.id}: ${r.message}`,"error")}(0,broadcast_1.broadcastStatus)(e,"completed",{duration:Date.now()-s});(0,broadcast_1.broadcastLog)(e,`Expired user blocks processing completed. Processed ${r.length} blocks`,"success")}catch(s){console_1.logger.error("CRON","Expired user blocks processing failed",s);(0,broadcast_1.broadcastStatus)(e,"failed");(0,broadcast_1.broadcastLog)(e,`Expired user blocks processing failed: ${s.message}`,"error");throw s}}Object.defineProperty(exports,"__esModule",{value:!0});exports.processExpiredUserBlocks=processExpiredUserBlocks;const db_1=require("@b/db"),console_1=require("@b/utils/console"),broadcast_1=require("../broadcast"),sequelize_1=require("sequelize");