"use strict";(()=>{var e={};e.id=691,e.ids=[691],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")},6249:(e,t)=>{Object.defineProperty(t,"l",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},5113:(e,t,r)=>{r.r(t),r.d(t,{config:()=>l,default:()=>d,routeModule:()=>f});var s={};r.r(s),r.d(s,{default:()=>c});var a=r(1802),n=r(7153),u=r(6249),i=r(2944),o=r(3481);async function c(e,t){if("POST"!==e.method)return t.status(405).json({success:!1,error:"Method not allowed"});if(!await (0,i.k)(e,t))return;let{id:r}=e.query;if("string"!=typeof r)return t.status(400).json({success:!1,error:"Invalid user ID"});try{let e=await o.K.toggleUserStatus(r);return t.status(200).json({success:!0,data:e})}catch(e){return console.error("Error toggling user status:",e),t.status(500).json({success:!1,error:"Failed to toggle user status"})}}let d=(0,u.l)(s,"default"),l=(0,u.l)(s,"config"),f=new a.PagesAPIRouteModule({definition:{kind:n.x.PAGES_API,page:"/api/v1/admin/users/[id]/toggle-status",pathname:"/api/v1/admin/users/[id]/toggle-status",bundlePath:"",filename:""},userland:s})},3481:(e,t,r)=>{r.d(t,{K:()=>n});var s=r(1450),a=r(1026);let n={async getUserById(e){let t=await s.Z.user.findUnique({where:{id:e},select:{id:!0,username:!0,avatarUrl:!0,role:!0,status:!0,createdAt:!0,lastLogin:!0}});return t?{...t,role:t.role,createdAt:t.createdAt.toISOString(),lastLogin:t.lastLogin?.toISOString()||new Date().toISOString(),avatarUrl:t.avatarUrl||""}:null},getUserByUsername:async e=>s.Z.user.findUnique({where:{username:e}}),async createUser(e,t,r){let n=await (0,a.c_)(t),u=`https://api.dicebear.com/7.x/avataaars/svg?seed=${e}`;return s.Z.user.create({data:{username:e,password:n,avatarUrl:u,role:"CREATOR",status:"ACTIVE"}})},async authenticateUser(e,t){let r=await this.getUserByUsername(e);return r&&r.password&&await (0,a.Gv)(t,r.password)?(await s.Z.user.update({where:{id:r.id},data:{lastLogin:new Date}}),{id:r.id,username:r.username,avatarUrl:r.avatarUrl||"",role:r.role,status:r.status,createdAt:r.createdAt.toISOString(),lastLogin:new Date().toISOString()}):null},getAllUsers:async()=>s.Z.user.findMany({orderBy:{createdAt:"desc"}}),updateUser:async(e,t)=>s.Z.user.update({where:{id:e},data:{username:t.username,avatarUrl:t.avatarUrl}}),updateUserRole:async(e,t)=>s.Z.user.update({where:{id:e},data:{role:t}}),async toggleUserStatus(e){let t=await s.Z.user.findUnique({where:{id:e}});if(!t)throw Error("User not found");let r="ACTIVE"===t.status?"BANNED":"ACTIVE";return s.Z.user.update({where:{id:e},data:{status:r}})}}},1026:(e,t,r)=>{r.d(t,{Gv:()=>c,RA:()=>d,WX:()=>l,c_:()=>o});var s=r(7096),a=r.n(s),n=r(9344),u=r.n(n);function i(){let e=process.env.JWT_SECRET;if(!e)throw Error("JWT_SECRET is not set");return e}async function o(e){return a().hash(e,10)}async function c(e,t){return a().compare(e,t)}function d(e){return u().sign({userId:e},i(),{expiresIn:"7d"})}function l(e){try{return u().verify(e,i())}catch(e){return null}}},2944:(e,t,r)=>{r.d(t,{k:()=>n});var s=r(8103),a=r(7556);async function n(e,t){return!!await (0,s.m)(e,t)&&(e.user?.role===a.i.ADMIN||(t.status(403).json({success:!1,error:"Admin access required"}),!1))}},8103:(e,t,r)=>{r.d(t,{R:()=>u,m:()=>n});var s=r(1026),a=r(3481);async function n(e,t){let r=i(e);if(!r)return t.status(401).json({success:!1,error:"Authentication required"}),!1;let n=(0,s.WX)(r);if(!n)return t.status(401).json({success:!1,error:"Invalid or expired token"}),!1;let u=await a.K.getUserById(n.userId);return u?"BANNED"===u.status?(t.status(403).json({success:!1,error:"Account has been banned"}),!1):(e.user=u,!0):(t.status(401).json({success:!1,error:"User not found"}),!1)}async function u(e){let t=i(e);if(!t)return;let r=(0,s.WX)(t);if(!r)return;let n=await a.K.getUserById(r.userId);n&&"BANNED"!==n.status&&(e.user=n)}function i(e){if(e.cookies.token)return e.cookies.token;let t=e.headers.authorization;return t&&t.startsWith("Bearer ")?t.substring(7):null}},1450:(e,t,r)=>{r.d(t,{Z:()=>a});var s=r(3524);let a=globalThis.prisma??new s.PrismaClient},7556:(e,t,r)=>{var s,a;r.d(t,{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={}))},7153:(e,t)=>{var r;Object.defineProperty(t,"x",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE"}(r||(r={}))},1802:(e,t,r)=>{e.exports=r(145)}};var t=require("../../../../../../webpack-api-runtime.js");t.C(e);var r=t(t.s=5113);module.exports=r})();