"use strict";(()=>{var e={};e.id=5453,e.ids=[5453,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")},59675:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>y,patchFetch:()=>T,requestAsyncStorage:()=>C,routeModule:()=>w,serverHooks:()=>g,staticGenerationAsyncStorage:()=>k});var r={};a.r(r),a.d(r,{PATCH:()=>f});var i=a(49303),n=a(88716),s=a(60670),l=a(87070),o=a(72331);let u=[{tier:"diamond",min:1e4},{tier:"platinum",min:4e3},{tier:"gold",min:1500},{tier:"silver",min:500},{tier:"bronze",min:0}],d={silver:"\uD83E\uDD48 Silver",gold:"\uD83E\uDD47 Gold",platinum:"\uD83D\uDC8E Platinum",diamond:"\uD83D\uDCA0 Diamond"},c=process.env.API_FOOTBALL_KEY||"",m=process.env.API_FOOTBALL_URL||"https://v3.football.api-sports.io";async function p(e){if(!c||!e)return null;try{let t=await fetch(`${m}/fixtures/events?fixture=${e}`,{headers:{"x-apisports-key":c}});if(!t.ok)return null;let a=((await t.json()).response||[]).filter(e=>"Goal"===e.type&&"Own Goal"!==e.detail).sort((e,t)=>(e.time?.elapsed??0)-(t.time?.elapsed??0));return a.length>0?a[0].player?.name??null:null}catch{return null}}async function h(e){if(!c||!e)return{totalCorners:null,totalCards:null};try{let t=await fetch(`${m}/fixtures/statistics?fixture=${e}`,{headers:{"x-apisports-key":c}});if(!t.ok)return{totalCorners:null,totalCards:null};let a=(await t.json()).response||[];if(0===a.length)return{totalCorners:null,totalCards:null};let r=0,i=0,n=!1;for(let e of a)for(let t of e.statistics||[])"Corner Kicks"===t.type&&null!==t.value&&(r+=parseInt(t.value)||0,n=!0),"Yellow Cards"===t.type&&null!==t.value&&(i+=parseInt(t.value)||0,n=!0),"Red Cards"===t.type&&null!==t.value&&(i+=parseInt(t.value)||0,n=!0);return n?{totalCorners:r,totalCards:i}:{totalCorners:null,totalCards:null}}catch{return{totalCorners:null,totalCards:null}}}async function f(e,{params:t}){try{let{status:a,home_score:r,away_score:i,half_time_home_score:n,half_time_away_score:s}=await e.json(),c=await o.prisma.match.findUnique({where:{id:t.id},select:{externalId:!0,homeTeamName:!0,awayTeamName:!0}}),m=c?.externalId??null,f=null!=r&&null!=i?r>0&&i>0:null,w=null,C=null,k=null;if(m&&"finished"===a){let[e,t]=await Promise.all([p(m),h(m)]);w=e,C=t.totalCorners,k=t.totalCards}await o.prisma.match.update({where:{id:t.id},data:{status:a??"finished",homeScore:r??null,awayScore:i??null,halfTimeHomeScore:n??null,halfTimeAwayScore:s??null,totalCorners:C,totalCards:k,firstGoalScorer:w,matchMvp:null,bothTeamsScored:f,isLocked:!0,updatedAt:new Date}});let g=0;if("finished"===a&&null!==r&&null!==i)for(let e of(await o.prisma.prediction.findMany({where:{matchId:t.id,calculatedAt:null}}))){let a=0,l={calculatedAt:new Date},m=await o.prisma.redemptionOrder.findFirst({where:{userId:e.userId,appliedAt:{gte:new Date(Date.now()-864e5)},item:{category:"boost"}},include:{item:!0}}),p=m?m.item.metadata?.multiplier??1:1;if(e.matchResult){let t=r>i?"home_win":r<i?"away_win":"draw",n=e.matchResult===t;l.matchResultCorrect=n,l.matchResultPoints=n?25:0,n&&(a+=25)}if(e.totalGoals){let t=(r??0)+(i??0)>2.5?"over_2_5":"under_2_5",n=e.totalGoals===t;l.totalGoalsCorrect=n,l.totalGoalsPoints=n?15:0,n&&(a+=15)}if(e.exactScore){let n=`${r}-${i}`,s=e.exactScore===n;if(l.exactScoreCorrect=s,l.exactScorePoints=s?100:0,s){a+=100;let n=`${c?.homeTeamName??"Tim Kandang"} vs ${c?.awayTeamName??"Tim Tandang"} (${r}-${i})`,s=o.prisma;await s.scoreReward.findFirst({where:{predictionId:e.id},select:{id:!0}}).catch(()=>null)||(await s.scoreReward.create({data:{userId:e.userId,predictionId:e.id,matchId:t.id,matchInfo:n,amount:25e3,status:"pending"}}).catch(()=>{}),await o.prisma.message.create({data:{threadId:`score-reward-${e.id}-${Date.now()}`,senderType:"system",recipientId:e.userId,subject:"\uD83C\uDFAF Selamat! Tebakan Skor Tepat!",content:`Selamat! Kamu berhasil menebak skor tepat pertandingan:

🏆 ${n}

Hadiah Rp 25.000 sedang diproses oleh admin. Kamu akan mendapat konfirmasi setelah admin menyetujui dan mengisikan hadiah ke akun MPO777 kamu.

Terima kasih sudah bermain di Bolafest! 🎉`}}).catch(()=>{}))}}if(e.bothTeamsScore&&null!==f){let t=f?"yes":"no",r=e.bothTeamsScore===t;l.bothTeamsScoreCorrect=r,l.bothTeamsScorePoints=r?15:0,r&&(a+=15)}if(e.firstGoalScorer&&w){let t=e.firstGoalScorer.toLowerCase()===w.toLowerCase();l.firstGoalScorerCorrect=t,l.firstGoalScorerPoints=t?200:0,t&&(a+=200)}if(e.halfTimeResult&&null!=n&&null!=s){let t=Number(n),r=Number(s),i=t>r?"home_win":t<r?"away_win":"draw",o=e.halfTimeResult===i;l.halfTimeResultCorrect=o,l.halfTimeResultPoints=o?25:0,o&&(a+=25)}if(e.totalCorners&&null!==C){let t=C>9.5?"over_9_5":"under_9_5",r=e.totalCorners===t;l.totalCornersCorrect=r,l.totalCornersPoints=r?15:0,r&&(a+=15)}if(e.totalCards&&null!==k){let t=k>3.5?"over_3_5":"under_3_5",r=e.totalCards===t;l.totalCardsCorrect=r,l.totalCardsPoints=r?15:0,r&&(a+=15)}p>1&&a>0&&(a=Math.round(a*p)),l.totalPointsEarned=a,await o.prisma.prediction.update({where:{id:e.id},data:l});let h=null!==e.exactScore?!0===l.exactScoreCorrect:a>0;if(a>0){let t=await o.prisma.user.findUnique({where:{id:e.userId}});if(t){let r=t.totalPoints+a,i=function(e){for(let{tier:t,min:a}of u)if(e>=a)return t;return"bronze"}(r),n=i!==t.rankTier,s=h?t.correctPredictions+1:t.correctPredictions,l=t.totalPredictions>0?parseFloat((s/t.totalPredictions*100).toFixed(1)):0;await o.prisma.user.update({where:{id:e.userId},data:{totalPoints:r,correctPredictions:s,accuracyRate:l,...n?{rankTier:i}:{}}}),await o.prisma.pointsLedger.create({data:{userId:e.userId,amount:a,type:"earned",source:"prediction",referenceId:e.id,description:`Prediksi benar - ${a} poin`,balanceAfter:r}}),n&&d[i]&&await o.prisma.message.create({data:{threadId:`rank-upgrade-${e.userId}-${i}-${Date.now()}`,senderType:"system",recipientId:e.userId,subject:`🎉 Selamat! Rank kamu naik ke ${d[i]}!`,content:`Kamu telah mencapai ${r.toLocaleString("id-ID")} poin dan berhasil naik ke rank ${d[i]}!

Sebagai penghargaan, kamu sekarang bisa menggunakan avatar rank ${i} di profil kamu.

Terus buat prediksi untuk naik ke rank berikutnya! 🚀`}}).catch(()=>{})}}g++}return l.NextResponse.json({success:!0,message:`Hasil disimpan. ${g} prediksi dihitung.`,predictions_calculated:g,auto_data:{both_teams_scored:f,first_goal_scorer:w,total_corners:C,total_cards:k}})}catch(e){return console.error("Match result PATCH error:",e),l.NextResponse.json({success:!1,message:"Gagal menyimpan hasil"},{status:500})}}let w=new i.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/admin/matches/[id]/result/route",pathname:"/api/admin/matches/[id]/result",filename:"route",bundlePath:"app/api/admin/matches/[id]/result/route"},resolvedPagePath:"C:\\xampp\\htdocs\\Bolafest\\app\\api\\admin\\matches\\[id]\\result\\route.ts",nextConfigOutput:"standalone",userland:r}),{requestAsyncStorage:C,staticGenerationAsyncStorage:k,serverHooks:g}=w,y="/api/admin/matches/[id]/result/route";function T(){return(0,s.patchFetch)({serverHooks:g,staticGenerationAsyncStorage:k})}},72331:(e,t,a)=>{a.d(t,{prisma:()=>i});var r=a(53524);let i=globalThis.prisma??new r.PrismaClient({log:["error"]})}};var t=require("../../../../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[9276,5972],()=>a(59675));module.exports=r})();