"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}});Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r);e[i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){e=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t};return e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(null!=t)for(var i=e(t),s=0;s<i.length;s++)"default"!==i[s]&&__createBinding(r,t,i[s]);__setModuleDefault(r,t);return r}}();Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const error_1=require("@b/utils/error"),db_1=require("@b/db"),XLSX=__importStar(require("xlsx")),fs=__importStar(require("fs")),path=__importStar(require("path")),demoMask_1=require("@b/utils/demoMask");exports.metadata={summary:"Export all users as an Excel file with detailed information",operationId:"exportUsersToExcel",tags:["Admin","CRM","User"],responses:{200:{description:"Excel file created successfully"}},requiresAuth:!0,permission:"view.user"};exports.default=async e=>{const{user:t}=e;if(!(null==t?void 0:t.id))throw(0,error_1.createError)({statusCode:401,message:"Unauthorized access"});const r=(await db_1.models.user.findAll({include:[{model:db_1.models.role,as:"role"},{model:db_1.models.kycApplication,as:"kyc"}]})).map(e=>{var t,r,i,s;return{ID:e.id,FirstName:e.firstName||"N/A",LastName:e.lastName||"N/A",Email:e.email||"N/A",EmailVerified:e.emailVerified?"Yes":"No",Phone:e.phone||"N/A",Role:(null===(t=e.role)||void 0===t?void 0:t.name)||"N/A",Status:e.status,KYC_Status:(null===(r=e.kyc)||void 0===r?void 0:r.status)||"N/A",CreatedAt:(null===(i=e.createdAt)||void 0===i?void 0:i.toISOString())||"N/A",LastLogin:(null===(s=e.lastLogin)||void 0===s?void 0:s.toISOString())||"N/A"}}),i=(0,demoMask_1.applyDemoMask)(r,["Email","Phone"]),s=XLSX.utils.json_to_sheet(i),o=XLSX.utils.book_new();XLSX.utils.book_append_sheet(o,s,"Users");const a=path.join(process.cwd(),"exports","users.xlsx");fs.mkdirSync(path.dirname(a),{recursive:!0});XLSX.writeFile(o,a);return{message:`Excel file created successfully at ${a}`}};