(()=>{var e={};e.id=6312,e.ids=[6312],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")},12909:(e,t,r)=>{"use strict";function s(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}function n(e){let t=e.headers.get("authorization");if(t&&t.startsWith("Bearer "))return t.slice(7);let r=e.cookies.get("admin_token")?.value;if(r)return r;let s=e.cookies.get("token")?.value;return s||null}r.d(t,{V:()=>n,u:()=>s})},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")},52442:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>g,routeModule:()=>k,serverHooks:()=>R,workAsyncStorage:()=>j,workUnitAsyncStorage:()=>v});var s={};r.r(s),r.d(s,{GET:()=>x,POST:()=>f});var n=r(96559),a=r(48088),i=r(37719),o=r(32190),u=r(43205),c=r.n(u),d=r(96330),p=r(12909);let l=new d.PrismaClient,m=(0,p.u)();async function x(e,{params:t}){try{let r,s=(0,p.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})}if(!r.userId)return o.NextResponse.json({error:"Unauthorized"},{status:401});let n=await Promise.resolve(t),a=parseInt(n.id);if(isNaN(a))return o.NextResponse.json({error:"Invalid ticket ID"},{status:400});if(!await l.ticket.findFirst({where:{id:a,userId:r.userId}}))return o.NextResponse.json({error:"Ticket not found"},{status:404});let i=await l.ticketMessage.findMany({where:{ticketId:a},include:{user:{select:{name:!0,surname:!0,email:!0}},globalAdmin:{select:{name:!0,surname:!0,email:!0}}},orderBy:{createdAt:"asc"}});return o.NextResponse.json({messages:i})}catch(e){return console.error("Get messages error:",e),o.NextResponse.json({error:"Server error"},{status:500})}finally{await l.$disconnect()}}async function f(e,{params:t}){try{let r,s=(0,p.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})}if(!r.userId)return o.NextResponse.json({error:"Unauthorized"},{status:401});let n=await Promise.resolve(t),a=parseInt(n.id);if(isNaN(a))return o.NextResponse.json({error:"Invalid ticket ID"},{status:400});let{message:i}=await e.json();if(!i||!i.trim())return o.NextResponse.json({error:"Mesaj gereklidir"},{status:400});let u=await l.ticket.findFirst({where:{id:a,userId:r.userId}});if(!u)return o.NextResponse.json({error:"Ticket not found"},{status:404});if("CLOSED"===u.status)return o.NextResponse.json({error:"Kapalı ticket'a mesaj eklenemez"},{status:400});let d=await l.ticketMessage.create({data:{ticketId:a,userId:r.userId,message:i.trim(),isFromAdmin:!1},include:{user:{select:{name:!0,surname:!0,email:!0}}}});return"RESOLVED"===u.status&&await l.ticket.update({where:{id:a},data:{status:"IN_PROGRESS"}}),o.NextResponse.json({message:d},{status:201})}catch(e){return console.error("Create message error:",e),o.NextResponse.json({error:"Server error"},{status:500})}finally{await l.$disconnect()}}let k=new n.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/tickets/[id]/messages/route",pathname:"/api/tickets/[id]/messages",filename:"route",bundlePath:"app/api/tickets/[id]/messages/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/tickets/[id]/messages/route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:j,workUnitAsyncStorage:v,serverHooks:R}=k;function g(){return(0,i.patchFetch)({workAsyncStorage:j,workUnitAsyncStorage:v})}},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),s=t.X(0,[4447,580,3205],()=>r(52442));module.exports=s})();