"use strict";(()=>{var e={};e.id=854,e.ids=[854],e.modules={3524:e=>{e.exports=require("@prisma/client")},7096:e=>{e.exports=require("bcrypt")},9344:e=>{e.exports=require("jsonwebtoken")},145:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},6213:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>c,routeModule:()=>m});var s={};t.r(s),t.d(s,{default:()=>d});var a=t(1802),i=t(7153),o=t(6249),u=t(8103),n=t(432),l=t(7556);async function d(e,r){let{id:t}=e.query;if("string"!=typeof t)return r.status(400).json({success:!1,error:"Invalid material ID"});if("GET"===e.method){await (0,u.R)(e);try{let e=await n.U.getMaterialById(t);if(!e)return r.status(404).json({success:!1,error:"Material not found"});return r.status(200).json({success:!0,data:e})}catch(e){return console.error("Error fetching material:",e),r.status(500).json({success:!1,error:"Failed to fetch material"})}}if("DELETE"===e.method){if(!await (0,u.m)(e,r))return;try{let s=await n.U.getMaterialById(t);if(!s)return r.status(404).json({success:!1,error:"Material not found"});if(s.author.id!==e.user.id&&e.user.role!==l.i.ADMIN)return r.status(403).json({success:!1,error:"Not authorized to delete this material"});return await n.U.deleteMaterial(t),r.status(200).json({success:!0,message:"Material deleted successfully"})}catch(e){return console.error("Error deleting material:",e),r.status(500).json({success:!1,error:"Failed to delete material"})}}return r.status(405).json({success:!1,error:"Method not allowed"})}let c=(0,o.l)(s,"default"),f=(0,o.l)(s,"config"),m=new a.PagesAPIRouteModule({definition:{kind:i.x.PAGES_API,page:"/api/v1/materials/[id]",pathname:"/api/v1/materials/[id]",bundlePath:"",filename:""},userland:s})},7556:(e,r,t)=>{var s,a;t.d(r,{i:()=>s}),function(e){e.USER="USER",e.ADMIN="ADMIN",e.CREATOR="CREATOR",e.MANAGER="MANAGER"}(s||(s={})),function(e){e.CODE="CODE",e.ASSET_ZIP="ASSET_ZIP",e.VIDEO="VIDEO"}(a||(a={}))}};var r=require("../../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[876],()=>t(6213));module.exports=s})();