"use strict";(()=>{var e={};e.id=4054,e.ids=[4054,2331],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")},95817:(e,r,t)=>{t.r(r),t.d(r,{originalPathname:()=>h,patchFetch:()=>m,requestAsyncStorage:()=>c,routeModule:()=>d,serverHooks:()=>v,staticGenerationAsyncStorage:()=>l});var s={};t.r(s),t.d(s,{POST:()=>p});var a=t(49303),o=t(88716),n=t(60670),u=t(87070),i=t(72331);async function p(e){try{let{code:r,amount:t}=await e.json();if(!r)return u.NextResponse.json({error:"Kode voucher kosong"},{status:400});let s=await i.default.voucher.findUnique({where:{code:r.toUpperCase()}});if(!s)return u.NextResponse.json({error:"Kode voucher tidak ditemukan"},{status:404});if(!s.isActive)return u.NextResponse.json({error:"Kode voucher sudah tidak aktif"},{status:400});if(s.maxUses>0&&s.usedCount>=s.maxUses)return u.NextResponse.json({error:"Kuota voucher sudah habis"},{status:400});if(s.expiresAt&&new Date>new Date(s.expiresAt))return u.NextResponse.json({error:"Kode voucher sudah kadaluarsa"},{status:400});let a=0;return(a="PERCENTAGE"===s.discountType?t*Number(s.discountValue)/100:Number(s.discountValue))>t&&(a=t),u.NextResponse.json({success:!0,voucherId:s.id,code:s.code,discountAmount:a,finalAmount:t-a})}catch(e){return console.error("Failed to validate voucher:",e),u.NextResponse.json({error:"Terjadi kesalahan pada server"},{status:500})}}let d=new a.AppRouteRouteModule({definition:{kind:o.x.APP_ROUTE,page:"/api/vouchers/validate/route",pathname:"/api/vouchers/validate",filename:"route",bundlePath:"app/api/vouchers/validate/route"},resolvedPagePath:"C:\\Users\\akmal\\OneDrive\\Documents\\AmaneNime Topup\\amanenime-topup\\app\\api\\vouchers\\validate\\route.ts",nextConfigOutput:"standalone",userland:s}),{requestAsyncStorage:c,staticGenerationAsyncStorage:l,serverHooks:v}=d,h="/api/vouchers/validate/route";function m(){return(0,n.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:l})}},72331:(e,r,t)=>{t.r(r),t.d(r,{default:()=>o,prisma:()=>a});var s=t(53524);let a=globalThis.prisma??new s.PrismaClient({datasources:{db:{url:(()=>{if(process.env.DATABASE_URL)return process.env.DATABASE_URL;let e=process.env.DB_USER||"root",r=process.env.DB_PASSWORD||"",t=process.env.DB_HOST||"127.0.0.1",s=process.env.DB_PORT||"3306",a=process.env.DB_NAME||"amanenime_topup";return`mysql://${e}:${r}@${t}:${s}/${a}`})()}},log:["error"]}),o=a}};var r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[8948,5972],()=>t(95817));module.exports=s})();