"use strict";(()=>{var e={};e.id=692,e.ids=[692],e.modules={53524:e=>{e.exports=require("@prisma/client")},98432:e=>{e.exports=require("bcryptjs")},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")},27790:e=>{e.exports=require("assert")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},17702:e=>{e.exports=require("events")},32615:e=>{e.exports=require("http")},35240:e=>{e.exports=require("https")},86624:e=>{e.exports=require("querystring")},17360:e=>{e.exports=require("url")},21764:e=>{e.exports=require("util")},71568:e=>{e.exports=require("zlib")},67590:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>m,patchFetch:()=>y,requestAsyncStorage:()=>N,routeModule:()=>E,serverHooks:()=>T,staticGenerationAsyncStorage:()=>x});var a={};r.r(a),r.d(a,{GET:()=>d,POST:()=>w});var s=r(73278),n=r(45002),o=r(54877),i=r(71309),p=r(18445),u=r(73275),c=r(82208),l=r(68172);async function w(e){try{let t=await (0,p.getServerSession)(u.Lz);if(!t?.user?.id||"company_admin"!==t.user.role)return i.NextResponse.json({error:"Unauthorized"},{status:401});let{transactionId:r,action:a}=await e.json();if(!r||!["approve","reject"].includes(a))return i.NextResponse.json({error:"Invalid request"},{status:400});let s=await c._.$queryRaw`
      SELECT wt.*, w.userType, w.tenantId, w.technicianId, w.userId
      FROM wallet_transactions wt
      JOIN wallets w ON wt.walletId = w.id
      WHERE wt.id = ${r} AND (wt.status = 'pending_approval' OR wt.transactionType = 'withdrawal')
      AND w.companyId = ${t.user.companyId}
    `;if(0===s.length)return i.NextResponse.json({error:"Transaction not found or not pending approval"},{status:404});let n=s[0];return"approve"===a?(await c._.$executeRaw`
        UPDATE wallet_transactions SET status = 'completed', updatedAt = NOW() WHERE id = ${r}
      `,"top_up"===n.transactionType?(await c._.$executeRaw`
          UPDATE wallets SET balance = balance + ${Math.abs(n.amount)}, updatedAt = NOW() WHERE id = ${n.walletId}
        `,await (0,l.yx)(r)):"withdrawal"===n.transactionType&&await (0,l.XV)(r)):"reject"===a&&(await c._.$executeRaw`
        UPDATE wallet_transactions SET status = 'rejected', updatedAt = NOW() WHERE id = ${r}
      `,"top_up"===n.transactionType?await (0,l.jJ)(r):"withdrawal"===n.transactionType&&(await c._.$executeRaw`
          UPDATE wallets SET balance = balance + ${Math.abs(n.amount)}, updatedAt = NOW() WHERE id = ${n.walletId}
        `,await (0,l.CR)(r))),i.NextResponse.json({message:"approve"===a?"Transaction approved successfully":"Transaction rejected"})}catch(e){return console.error("Error processing transaction approval:",e),i.NextResponse.json({error:"Internal server error"},{status:500})}}async function d(e){try{let e=await (0,p.getServerSession)(u.Lz);if(!e?.user?.id||"company_admin"!==e.user.role)return i.NextResponse.json({error:"Unauthorized"},{status:401});let t=await c._.$queryRaw`
      SELECT
        wt.*,
        w.userType,
        CASE
          WHEN w.userType = 'tenant' THEN t.firstName || ' ' || t.lastName
          WHEN w.userType = 'technician' THEN tec.firstName || ' ' || tec.lastName
          WHEN w.userType = 'user' THEN u.firstName || ' ' || u.lastName
        END as userName,
        CASE
          WHEN w.userType = 'tenant' THEN t.email
          WHEN w.userType = 'technician' THEN tec.email
          WHEN w.userType = 'user' THEN u.email
        END as userEmail
      FROM wallet_transactions wt
      JOIN wallets w ON wt.walletId = w.id
      LEFT JOIN tenants t ON w.userType = 'tenant' AND w.tenantId = t.id
      LEFT JOIN technicians tec ON w.userType = 'technician' AND w.technicianId = tec.id
      LEFT JOIN users u ON w.userType = 'user' AND w.userId = u.id
      WHERE (wt.status = 'pending_approval' OR (wt.transactionType = 'withdrawal' AND wt.status = 'pending'))
      AND w.companyId = ${e.user.companyId}
      ORDER BY wt.createdAt DESC
    `;return i.NextResponse.json({transactions:t})}catch(e){return console.error("Error fetching pending transactions:",e),i.NextResponse.json({error:"Internal server error"},{status:500})}}let E=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/wallet/approve/route",pathname:"/api/wallet/approve",filename:"route",bundlePath:"app/api/wallet/approve/route"},resolvedPagePath:"c:\\xampp\\htdocs\\propmaster.io\\src\\app\\api\\wallet\\approve\\route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:N,staticGenerationAsyncStorage:x,serverHooks:T}=E,m="/api/wallet/approve/route";function y(){return(0,o.patchFetch)({serverHooks:T,staticGenerationAsyncStorage:x})}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[7787,9121,4833,3976],()=>r(67590));module.exports=a})();