(()=>{var e={};e.id=6646,e.ids=[6646],e.modules={3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},5486:e=>{"use strict";e.exports=require("bcrypt")},10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},12909:(e,r,t)=>{"use strict";function s(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}function a(e){let r=e.headers.get("authorization");if(r&&r.startsWith("Bearer "))return r.slice(7);let t=e.cookies.get("admin_token")?.value;if(t)return t;let s=e.cookies.get("token")?.value;return s||null}t.d(r,{V:()=>a,u:()=>s})},16472:(e,r,t)=>{"use strict";t.r(r),t.d(r,{patchFetch:()=>v,routeModule:()=>x,serverHooks:()=>w,workAsyncStorage:()=>h,workUnitAsyncStorage:()=>f});var s={};t.r(s),t.d(s,{GET:()=>y,POST:()=>k});var a=t(96559),n=t(48088),i=t(37719),o=t(32190),u=t(96330),p=t(43205),c=t.n(p),l=t(12909);let d=new u.PrismaClient,m=(0,l.u)();async function y(e){try{let r,t=(0,l.V)(e);if(!t)return o.NextResponse.json({error:"Unauthorized"},{status:401});try{r=c().verify(t,m)}catch(e){return o.NextResponse.json({error:"Invalid token"},{status:401})}let s=r.companyId;if(!s)return o.NextResponse.json({error:"Invalid payload"},{status:400});let a=await d.user.findMany({where:{companyId:s},include:{userMarketplacePermissions:{include:{companyMarketplace:{include:{marketplace:!0}}}}},orderBy:{id:"asc"}}),n=a.map(e=>e.id),i=await d.userSystemPermission.findMany({where:{userId:{in:n}},select:{userId:!0,permission:!0}}),u=new Map;i.forEach(e=>{let r=u.get(e.userId)||[];r.push(e.permission),u.set(e.userId,r)});let p=a.map(e=>({id:e.id,name:e.name,surname:e.surname,email:e.email,isAdmin:e.isAdmin,marketplaces:e.userMarketplacePermissions.map(e=>({id:e.companyMarketplace.id,name:e.companyMarketplace.name,marketplaceId:e.companyMarketplace.marketplace.id,marketplaceName:e.companyMarketplace.marketplace.name.toLowerCase(),bgColor:e.companyMarketplace.marketplace.bgColor,icon:e.companyMarketplace.marketplace.icon})),systemPermissions:u.get(e.id)||[]}));return o.NextResponse.json({users:p})}catch(e){return console.error("Company users error:",e),o.NextResponse.json({error:"Server error"},{status:500})}}async function k(e){try{let r,s=(0,l.V)(e);if(!s)return o.NextResponse.json({error:"Unauthorized"},{status:401});try{r=c().verify(s,m)}catch{return o.NextResponse.json({error:"Invalid token"},{status:401})}let a=r.companyId,n=r.userId;if(!(await d.userSystemPermission.findMany({where:{userId:n},select:{permission:!0}})).some(e=>"USER_MANAGEMENT"===e.permission))return o.NextResponse.json({error:"Bu işlem i\xe7in yetkiniz bulunmuyor"},{status:403});let{email:i,password:u,name:p,surname:y,phoneNumber:k,isAdmin:x,marketplaceIds:h,systemPermissions:f}=await e.json();if(!i||!u||!p||!y)return o.NextResponse.json({error:"Zorunlu alanlar eksik"},{status:400});let w=(await Promise.resolve().then(t.t.bind(t,5486,23))).default,v=await w.hash(u,10),M=await d.user.create({data:{email:i,password:v,name:p,surname:y,phoneNumber:k||"",companyId:a,isAdmin:!!x}});if(Array.isArray(h)&&h.length>0){let e=await d.companyMarketplace.findMany({where:{companyId:a,id:{in:h}}});await d.userMarketplacePermission.createMany({data:e.map(e=>({userId:M.id,companyMarketplaceId:e.id}))})}return Array.isArray(f)&&f.length>0&&await d.userSystemPermission.createMany({data:f.map(e=>({userId:M.id,permission:e}))}),o.NextResponse.json({id:M.id})}catch(e){return console.error("Create user error:",e),o.NextResponse.json({error:"Server error"},{status:500})}}let x=new a.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/company/users/route",pathname:"/api/company/users",filename:"route",bundlePath:"app/api/company/users/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/company/users/route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:h,workUnitAsyncStorage:f,serverHooks:w}=x;function v(){return(0,i.patchFetch)({workAsyncStorage:h,workUnitAsyncStorage:f})}},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")},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 r=require("../../../../webpack-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4447,580,3205],()=>t(16472));module.exports=s})();