"use strict";(()=>{var e={};e.id=3587,e.ids=[3587],e.modules={53524:e=>{e.exports=require("@prisma/client")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},6113:e=>{e.exports=require("crypto")},13685:e=>{e.exports=require("http")},95687:e=>{e.exports=require("https")},85477:e=>{e.exports=require("punycode")},12781:e=>{e.exports=require("stream")},57310:e=>{e.exports=require("url")},59796:e=>{e.exports=require("zlib")},25319:(e,t,n)=>{n.r(t),n.d(t,{originalPathname:()=>g,patchFetch:()=>h,requestAsyncStorage:()=>S,routeModule:()=>l,serverHooks:()=>m,staticGenerationAsyncStorage:()=>E});var r={};n.r(r),n.d(r,{GET:()=>c,dynamic:()=>u});var a=n(49303),s=n(88716),o=n(60670),p=n(87070),d=n(13538),i=n(78837);let u="force-dynamic";async function c(e){try{let t=e.headers.get("Authorization"),n=process.env.CRON_SECRET;if(n&&t!==`Bearer ${n}`){let e=process.env.ATLAS_DEVICE_API_KEY;if(e&&t!==`Bearer ${e}`)return p.NextResponse.json({error:"Unauthorized"},{status:401})}let r=new Date;r.setUTCHours(0,0,0,0);let a=await d.Z.student.findMany({select:{id:!0,name:!0,surname:!0,classId:!0}}),s=await d.Z.gateScan.findMany({where:{date:r},select:{studentId:!0}}),o=new Set(s.map(e=>e.studentId)),u=a.filter(e=>!o.has(e.id));if(0===u.length)return p.NextResponse.json({message:"All students scanned — no absences to mark",date:r.toISOString(),totalStudents:a.length,absentCount:0});let c=u.map(e=>({studentId:e.id,timestamp:new Date,date:r,status:"ABSENT",confidence:0,deviceId:"SYSTEM-SWEEP"})),l=await d.Z.gateScan.createMany({data:c,skipDuplicates:!0});try{await i.on.trigger(i.pD.admin,i.FP.STATUS_CHANGED,{type:"sweep",date:r.toISOString(),absentCount:l.count,totalStudents:a.length,presentCount:a.length-l.count,message:`Attendance sweep: ${l.count} students marked absent`})}catch{}return p.NextResponse.json({message:`Sweep complete: ${l.count} students marked absent`,date:r.toISOString(),totalStudents:a.length,absentCount:l.count,presentCount:o.size})}catch(e){return console.error("[AttendanceSweep] Error:",e),p.NextResponse.json({error:"Internal Server Error",message:String(e)},{status:500})}}let l=new a.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/cron/attendance-sweep/route",pathname:"/api/cron/attendance-sweep",filename:"route",bundlePath:"app/api/cron/attendance-sweep/route"},resolvedPagePath:"C:\\School Management System\\Working\\V2\\src\\app\\api\\cron\\attendance-sweep\\route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:S,staticGenerationAsyncStorage:E,serverHooks:m}=l,g="/api/cron/attendance-sweep/route";function h(){return(0,o.patchFetch)({serverHooks:m,staticGenerationAsyncStorage:E})}},13538:(e,t,n)=>{n.d(t,{Z:()=>a});var r=n(53524);let a=globalThis.prisma??new r.PrismaClient({log:["error"],datasources:{db:{url:process.env.DATABASE_URL}}})},78837:(e,t,n)=>{n.d(t,{FP:()=>o,on:()=>a,pD:()=>s});var r=n(89759);let a=new(n.n(r)())({appId:process.env.PUSHER_APP_ID||"",key:process.env.NEXT_PUBLIC_PUSHER_APP_KEY||"",secret:process.env.PUSHER_SECRET||"",cluster:process.env.PUSHER_CLUSTER||"ap2",useTLS:!0}),s={admin:"attendance-admin",teacher:e=>`attendance-teacher-${e}`,student:e=>`attendance-student-${e}`},o={SCAN_RECEIVED:"scan-received",HEARTBEAT_UPDATE:"heartbeat-update",STATUS_CHANGED:"status-changed"};process.env.NEXT_PUBLIC_PUSHER_APP_KEY,process.env.PUSHER_CLUSTER}};var t=require("../../../../webpack-runtime.js");t.C(e);var n=e=>t(t.s=e),r=t.X(0,[8948,7070,2830],()=>n(25319));module.exports=r})();