"use strict";(()=>{var e={};e.id=5305,e.ids=[5305],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")},8420:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>m,patchFetch:()=>x,requestAsyncStorage:()=>d,routeModule:()=>c,serverHooks:()=>v,staticGenerationAsyncStorage:()=>l});var a={};r.r(a),r.d(a,{POST:()=>u});var s=r(49303),i=r(88716),n=r(60670),o=r(87070),p=r(72331);async function u(e){try{let{userId:t,packageId:r}=await e.json();if(!t||!r)return o.NextResponse.json({error:"Missing parameters"},{status:400});let a=await p._.vipPackage.findUnique({where:{id:r}});if(!a)return o.NextResponse.json({error:"Invalid package"},{status:400});let s=await p._.user.findUnique({where:{id:t}});if(!s)return o.NextResponse.json({error:"User not found"},{status:404});if(s.coins<a.price)return o.NextResponse.json({error:"Koin tidak cukup. Silakan Topup."},{status:402});let i=new Date;return s.vipExpiresAt&&s.vipExpiresAt>new Date&&(i=new Date(s.vipExpiresAt)),i.setDate(i.getDate()+a.days),await p._.$transaction([p._.user.update({where:{id:t},data:{coins:{decrement:a.price},vipLevel:a.level||1,vipExpiresAt:i}}),p._.transaction.create({data:{userId:t,type:"VIP_PURCHASE",amount:0,coins:-a.price,status:"SUCCESS",description:`Beli Paket ${a.name}`}})]),a.coins>0&&await p._.$transaction([p._.user.update({where:{id:t},data:{coins:{increment:a.coins}}}),p._.transaction.create({data:{userId:t,type:"VIP_BONUS",amount:0,coins:a.coins,status:"SUCCESS",description:`Bonus Koin dari Paket ${a.name}`}})]),o.NextResponse.json({success:!0,packageName:a.name,expiresAt:i})}catch(e){return console.error("VIP Purchase Error:",e),o.NextResponse.json({error:"Internal Server Error"},{status:500})}}let c=new s.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/vip/buy/route",pathname:"/api/vip/buy",filename:"route",bundlePath:"app/api/vip/buy/route"},resolvedPagePath:"C:\\Users\\MSI\\Downloads\\film\\app\\api\\vip\\buy\\route.ts",nextConfigOutput:"standalone",userland:a}),{requestAsyncStorage:d,staticGenerationAsyncStorage:l,serverHooks:v}=c,m="/api/vip/buy/route";function x(){return(0,n.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:l})}},72331:(e,t,r)=>{r.d(t,{_:()=>s});var a=r(53524);let s=global.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],()=>r(8420));module.exports=a})();