(()=>{var e={};e.id=4272,e.ids=[4272],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 i(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:()=>i,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")},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")},84103:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>h,routeModule:()=>g,serverHooks:()=>w,workAsyncStorage:()=>k,workUnitAsyncStorage:()=>v});var s={};r.r(s),r.d(s,{POST:()=>f});var i=r(96559),a=r(48088),n=r(37719),o=r(32190),u=r(43205),d=r.n(u),c=r(96330),l=r(12909);let p=new c.PrismaClient,m=(0,l.u)();async function x(e){let t=(0,l.V)(e);if(!t)return null;try{let e=d().verify(t,m);if(e.isGlobalAdmin&&e.globalAdminId)return e}catch{}return null}async function f(e,{params:t}){try{let r=await x(e);if(!r)return o.NextResponse.json({error:"Unauthorized"},{status:401});let s=await Promise.resolve(t),i=parseInt(s.id);if(isNaN(i))return o.NextResponse.json({error:"Invalid ticket ID"},{status:400});let{message:a}=await e.json();if(!a||!a.trim())return o.NextResponse.json({error:"Mesaj gereklidir"},{status:400});let n=await p.ticket.findUnique({where:{id:i}});if(!n)return o.NextResponse.json({error:"Ticket not found"},{status:404});if("CLOSED"===n.status)return o.NextResponse.json({error:"Kapalı ticket'a mesaj eklenemez"},{status:400});let u=await p.ticketMessage.create({data:{ticketId:i,globalAdminId:r.globalAdminId,message:a.trim(),isFromAdmin:!0},include:{globalAdmin:{select:{name:!0,surname:!0,email:!0}}}});return await p.ticket.update({where:{id:i},data:{status:"OPEN"===n.status?"IN_PROGRESS":n.status}}),await p.$disconnect(),o.NextResponse.json({message:u},{status:201})}catch(e){return console.error("Create admin message error:",e),await p.$disconnect(),o.NextResponse.json({error:"Server error"},{status:500})}}let g=new i.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/admin/tickets/[id]/messages/route",pathname:"/api/admin/tickets/[id]/messages",filename:"route",bundlePath:"app/api/admin/tickets/[id]/messages/route"},resolvedPagePath:"/Users/mustafaseyhan/Project/PazarAnalist/src/app/api/admin/tickets/[id]/messages/route.ts",nextConfigOutput:"standalone",userland:s}),{workAsyncStorage:k,workUnitAsyncStorage:v,serverHooks:w}=g;function h(){return(0,n.patchFetch)({workAsyncStorage:k,workUnitAsyncStorage:v})}},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(84103));module.exports=s})();