"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const error_1=require("@b/utils/error"),promises_1=__importDefault(require("fs/promises")),path_1=__importDefault(require("path")),constants_1=require("@b/utils/constants");exports.metadata={summary:"Retrieves the email wrapper template HTML",operationId:"getEmailWrapperTemplate",tags:["Admin","Notifications"],permission:"view.notification.template",responses:{200:{description:"Email wrapper template retrieved successfully",content:{"application/json":{schema:{type:"object",properties:{html:{type:"string",description:"The HTML content of the email wrapper template"}}}}}},401:{description:"Unauthorized, permission required to view notification"},404:{description:"Email wrapper template not found"},500:{description:"Internal server error"}},requiresAuth:!0};exports.default=async()=>{try{let e;e=constants_1.isProduction?path_1.default.join(process.cwd(),"backend","email","templates","generalTemplate.html"):path_1.default.join(constants_1.baseUrl,"email","templates","generalTemplate.html");const t=async e=>{try{await promises_1.default.access(e);return!0}catch(e){return!1}};if(!await t(e)){const a=[path_1.default.join(process.cwd(),"email","templates","generalTemplate.html"),path_1.default.join(__dirname,"../../../../../email","templates","generalTemplate.html"),path_1.default.join(__dirname,"../../../../email","templates","generalTemplate.html")],r=(await Promise.all(a.map(async e=>({path:e,exists:await t(e)})))).find(e=>e.exists);r&&(e=r.path)}return{html:await promises_1.default.readFile(e,"utf-8")}}catch(e){if("ENOENT"===e.code)throw(0,error_1.createError)({statusCode:404,message:"Email wrapper template not found"});throw(0,error_1.createError)({statusCode:500,message:"Failed to read email wrapper template"})}};