"use strict";exports.id=4615,exports.ids=[4615],exports.modules={14615:(e,t,n)=>{n.d(t,{U9:()=>l,awardLoyaltyPoints:()=>u,cg:()=>p,getLoyaltySettings:()=>o,redeemLoyaltyPoints:()=>s,validateRedemption:()=>m});var i=n(8194),a=n(14709);let r=[{name:"Member",minLifetimePoints:0,earningMultiplier:1},{name:"Silver",minLifetimePoints:100,earningMultiplier:1.25},{name:"Gold",minLifetimePoints:500,earningMultiplier:1.5},{name:"Platinum",minLifetimePoints:1e3,earningMultiplier:2}];async function o(e){let t=await (0,a.fO)(e);return{enabled:"true"===t.loyalty_enabled,pointsPerAmount:parseInt(t.loyalty_points_per_amount||"1"),amountPerPoint:parseInt(t.loyalty_amount_per_point||"10000"),redemptionValue:parseInt(t.loyalty_redemption_value||"500"),minRedemption:parseInt(t.loyalty_min_redemption||"10"),maxRedemption:parseInt(t.loyalty_max_redemption||"0")}}function l(e){let t=r[0];for(let n of r)e>=n.minLifetimePoints&&(t=n);return t}function d(e,t){return e*t.redemptionValue}function m(e,t,n,i){return e<=0?{valid:!1,error:"Jumlah poin harus lebih dari 0"}:e>t?{valid:!1,error:"Saldo poin tidak mencukupi"}:n.minRedemption>0&&e<n.minRedemption?{valid:!1,error:`Minimum penukaran adalah ${n.minRedemption} poin`}:n.maxRedemption>0&&e>n.maxRedemption?{valid:!1,error:`Maksimum penukaran adalah ${n.maxRedemption} poin`}:d(e,n)>i?{valid:!1,error:"Diskon melebihi subtotal pesanan"}:{valid:!0}}async function u(e,t,n,a){var r;let d=await o(n);if(!d.enabled)return null;let m=await i._.customer.findFirst({where:{id:e,tenantId:n}});if(!m)return null;let u=(r=m.lifetimePoints,Math.floor(Math.floor(a/d.amountPerPoint)*d.pointsPerAmount*l(r).earningMultiplier));if(u<=0)return null;let s=m.loyaltyPoints,p=s+u,y=l(m.lifetimePoints+u);return await i._.$transaction([i._.loyaltyTransaction.create({data:{tenantId:n,customerId:e,orderId:t,type:"earn",points:u,balanceBefore:s,balanceAfter:p,description:"Poin dari pesanan"}}),i._.customer.update({where:{id:e},data:{loyaltyPoints:{increment:u},lifetimePoints:{increment:u}}}),i._.order.update({where:{id:t},data:{loyaltyPointsEarned:u}})]),{pointsEarned:u,newBalance:p,tier:y}}async function s(e,t,n,a){let r=await o(n);if(!r.enabled)return null;let l=await i._.customer.findFirst({where:{id:e,tenantId:n}});if(!l)return null;let m=d(a,r),u=l.loyaltyPoints,s=u-a;return await i._.$transaction([i._.loyaltyTransaction.create({data:{tenantId:n,customerId:e,orderId:t,type:"redeem",points:-a,balanceBefore:u,balanceAfter:s,description:"Penukaran poin untuk pesanan"}}),i._.customer.update({where:{id:e},data:{loyaltyPoints:{decrement:a}}}),i._.order.update({where:{id:t},data:{loyaltyPointsRedeemed:a}})]),{discount:m,newBalance:s}}async function p(e,t,n,a){let r=(await i._.customer.findFirstOrThrow({where:{id:e,tenantId:t}})).loyaltyPoints,o=r+n,l={loyaltyPoints:{increment:n}};return n>0&&(l.lifetimePoints={increment:n}),await i._.$transaction([i._.loyaltyTransaction.create({data:{tenantId:t,customerId:e,orderId:null,type:"adjust",points:n,balanceBefore:r,balanceAfter:o,description:a}}),i._.customer.update({where:{id:e},data:l})]),{newBalance:o}}}};