"use strict";(()=>{var e={};e.id=9955,e.ids=[9955],e.modules={72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},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")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},76162:e=>{e.exports=require("stream")},21764:e=>{e.exports=require("util")},45143:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>x,requestAsyncStorage:()=>p,routeModule:()=>d,serverHooks:()=>w,staticGenerationAsyncStorage:()=>m});var a={};r.r(a),r.d(a,{GET:()=>c});var n=r(49303),s=r(88716),i=r(60670),o=r(87070),u=r(8194),l=r(95456);async function c(e){try{let t=await (0,l.ts)();if(!t)return o.NextResponse.json({error:"Unauthorized"},{status:401});let r=parseInt(e.nextUrl.searchParams.get("page")||"1"),a=parseInt(e.nextUrl.searchParams.get("limit")||"20"),n=(r-1)*a,s={tenantId:t.tenantId},i={wallet:{tenantId:t.tenantId}},[c,d,p,m,w]=await Promise.all([u._.tenantWallet.findUnique({where:s}),u._.walletTransaction.findMany({where:i,orderBy:{createdAt:"desc"},take:a,skip:n,include:{paymentTransaction:{select:{referenceId:!0,paymentChannel:!0,order:{select:{orderNumber:!0}}}},withdrawalRequest:{select:{id:!0,bankName:!0,status:!0}}}}),u._.walletTransaction.count({where:i}),u._.walletTransaction.aggregate({where:{...i,type:"credit"},_sum:{amount:!0}}),u._.walletTransaction.aggregate({where:{...i,type:"debit"},_sum:{amount:!0}})]);return o.NextResponse.json({balance:c?Number(c.balance):0,totalIncome:Number(m._sum.amount||0),totalWithdrawn:Number(w._sum.amount||0),transactions:d.map(e=>({id:e.id,type:e.type,amount:Number(e.amount),balanceAfter:Number(e.balanceAfter),description:e.description,createdAt:e.createdAt,orderNumber:e.paymentTransaction?.order?.orderNumber,paymentChannel:e.paymentTransaction?.paymentChannel,withdrawalBank:e.withdrawalRequest?.bankName,withdrawalStatus:e.withdrawalRequest?.status})),pagination:{page:r,limit:a,total:p,totalPages:Math.ceil(p/a)}})}catch{return o.NextResponse.json({error:"Server error"},{status:500})}}let d=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/wallet/route",pathname:"/api/wallet",filename:"route",bundlePath:"app/api/wallet/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\wallet\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:p,staticGenerationAsyncStorage:m,serverHooks:w}=d,h="/api/wallet/route";function x(){return(0,i.patchFetch)({serverHooks:w,staticGenerationAsyncStorage:m})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>d,MH:()=>h,PT:()=>x,RA:()=>p,WX:()=>m,c_:()=>c,ts:()=>w});var a=r(41482),n=r.n(a),s=r(42023),i=r.n(s),o=r(71615),u=r(8194);let l=process.env.JWT_SECRET||"fallback-secret-change-me";async function c(e){return i().hash(e,12)}async function d(e,t){return i().compare(e,t)}function p(e){return n().sign(e,l,{expiresIn:"7d"})}function m(e){try{return n().verify(e,l)}catch{return null}}async function w(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=m(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function h(e,t){return t.includes(e)}function x(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>n});let a=require("@prisma/client"),n=globalThis.prisma??new a.PrismaClient}};var t=require("../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8948,5972,4261,2023],()=>r(45143));module.exports=a})();