(()=>{var e={};e.id=9705,e.ids=[9705],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},27910:e=>{"use strict";e.exports=require("stream")},28354:e=>{"use strict";e.exports=require("util")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},46666:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>g,routeModule:()=>m,serverHooks:()=>x,workAsyncStorage:()=>y,workUnitAsyncStorage:()=>f});var a={};r.r(a),r.d(a,{GET:()=>k});var o=r(96559),s=r(48088),p=r(37719),n=r(32190),c=r(96330),i=r(43205),u=r.n(i);let d=new c.PrismaClient,l=process.env.JWT_SECRET||"your-secret-key";async function k(e){try{let t,r=e.headers.get("authorization");if(!r||!r.startsWith("Bearer "))return n.NextResponse.json({error:"Unauthorized"},{status:401});let a=r.substring(7);try{t=u().verify(a,l)}catch(e){return n.NextResponse.json({error:"Invalid token"},{status:401})}if(!t||!t.userId)return n.NextResponse.json({error:"Invalid token"},{status:401});let{searchParams:o}=new URL(e.url),s=parseInt(o.get("limit")||"10"),p=o.get("companyMarketplaceId"),c=await d.user.findUnique({where:{id:t.userId},include:{company:!0}});if(!c||!c.company)return n.NextResponse.json({error:"User or company not found"},{status:404});let i={productMarketplace:{product:{companyId:c.companyId}},netProfit:{not:null}};p&&(i.productMarketplace.companyMarketplaceId=parseInt(p));let k=(await d.productAnalysis.findMany({where:i,orderBy:{netProfit:"desc"},take:s,include:{productMarketplace:{include:{product:{select:{id:!0,title:!0,category:!0,brand:!0,stockCode:!0}},companyMarketplace:{include:{marketplace:{select:{name:!0,bgColor:!0}}}}}}}})).map(e=>({id:e.id,productId:e.productMarketplace.product.id,name:e.productMarketplace.product.title,category:e.productMarketplace.product.category||"Genel",brand:e.productMarketplace.product.brand,stockCode:e.productMarketplace.product.stockCode,profit:e.netProfit,profitRate:e.netProfitRate,price:e.discountedPrice||e.salePrice,marketplace:e.productMarketplace.companyMarketplace.marketplace.name,marketplaceColor:e.productMarketplace.companyMarketplace.marketplace.bgColor,buyboxRank:e.buyboxRank,isActiveOnMarketplace:e.isActiveOnMarketplace,updatedAt:e.updatedAt}));return n.NextResponse.json({products:k,total:k.length})}catch(e){return console.error("Error fetching top profitable products:",e),n.NextResponse.json({error:"Failed to fetch top profitable products"},{status:500})}finally{await d.$disconnect()}}let m=new o.AppRouteRouteModule({definition:{kind:s.RouteKind.APP_ROUTE,page:"/api/products/top-profitable/route",pathname:"/api/products/top-profitable",filename:"route",bundlePath:"app/api/products/top-profitable/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/products/top-profitable/route.ts",nextConfigOutput:"standalone",userland:a}),{workAsyncStorage:y,workUnitAsyncStorage:f,serverHooks:x}=m;function g(){return(0,p.patchFetch)({workAsyncStorage:y,workUnitAsyncStorage:f})}},55511:e=>{"use strict";e.exports=require("crypto")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},78335:()=>{},79428:e=>{"use strict";e.exports=require("buffer")},96330:e=>{"use strict";e.exports=require("@prisma/client")},96487:()=>{}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[4447,580,3205],()=>r(46666));module.exports=a})();