"use strict";(()=>{var e={};e.id=3609,e.ids=[3609],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")},89439:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>m,patchFetch:()=>g,requestAsyncStorage:()=>v,routeModule:()=>E,serverHooks:()=>h,staticGenerationAsyncStorage:()=>P});var a={};r.r(a),r.d(a,{GET:()=>l,POST:()=>d,dynamic:()=>c});var s=r(49303),n=r(88716),o=r(60670),i=r(87070),u=r(13538),p=r(78837);let c="force-dynamic";async function d(e){try{let t=e.headers.get("Authorization"),r=process.env.ATLAS_DEVICE_API_KEY;if(r&&(t?.startsWith("Bearer ")?t.slice(7):"")!==r)return i.NextResponse.json({error:"Unauthorized"},{status:401});let{deviceId:a,status:s="online",metadata:n}=await e.json();if(!a)return i.NextResponse.json({error:"Bad Request",message:"deviceId is required"},{status:400});let o=await u.Z.deviceHeartbeat.upsert({where:{deviceId:a},update:{lastPing:new Date,status:s,metadata:n?JSON.stringify(n):void 0},create:{deviceId:a,status:s,metadata:n?JSON.stringify(n):null}});try{await p.on.trigger(p.pD.admin,p.FP.HEARTBEAT_UPDATE,{deviceId:a,status:s,lastPing:o.lastPing.toISOString(),metadata:n})}catch{}return i.NextResponse.json({message:"Heartbeat received",heartbeat:o},{status:200})}catch(e){return console.error("[Heartbeat] Error:",e),i.NextResponse.json({error:"Internal Server Error",message:String(e)},{status:500})}}async function l(){try{let e=await u.Z.deviceHeartbeat.findMany({orderBy:{lastPing:"desc"}}),t=Date.now(),r=e.map(e=>({...e,computedStatus:t-new Date(e.lastPing).getTime()>12e4?"offline":e.status}));return i.NextResponse.json({devices:r},{status:200})}catch(e){return console.error("[Heartbeat] GET Error:",e),i.NextResponse.json({error:"Internal Server Error"},{status:500})}}let E=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/v1/sync/heartbeat/route",pathname:"/api/v1/sync/heartbeat",filename:"route",bundlePath:"app/api/v1/sync/heartbeat/route"},resolvedPagePath:"C:\\School Management System\\Working\\V2\\src\\app\\api\\v1\\sync\\heartbeat\\route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:v,staticGenerationAsyncStorage:P,serverHooks:h}=E,m="/api/v1/sync/heartbeat/route";function g(){return(0,o.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:P})}},13538:(e,t,r)=>{r.d(t,{Z:()=>s});var a=r(53524);let s=globalThis.prisma??new a.PrismaClient({log:["error"],datasources:{db:{url:process.env.DATABASE_URL}}})},78837:(e,t,r)=>{r.d(t,{FP:()=>o,on:()=>s,pD:()=>n});var a=r(89759);let s=new(r.n(a)())({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}),n={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 r=e=>t(t.s=e),a=t.X(0,[8948,7070,2830],()=>r(89439));module.exports=a})();