var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import string from '@adonisjs/core/helpers/string';
import app from '@adonisjs/core/services/app';
import router from '@adonisjs/core/services/router';
import '@akago/vine-lucid';
import edge from 'edge.js';
import '../../lib/vine_types/vine_sirene.js';
import { AKEmailService } from '../email/email_service.js';
import { AKAPIException } from '../exceptions/api_exception.js';
import { OpenApiDescription, OpenApiName } from '../openapi/openapi_router_macros.js';
export default class AKEventController {
    async list({}) {
        const eventService = await app.container.make('akago.event.service');
        return eventService.emailPreviewEvents
            .filter((e) => e.shouldSendViaChannels().includes('email'))
            .map((e, i) => {
            const url = router.builder().params([e.constructor.name]).make('event.email.preview');
            return `<h4>${i + 1}. ${string.sentenceCase(e.constructor.name)}</h4><a href="${url}">view email template</a>`;
        })
            .join('</br></br>');
    }
    async previewEmail({ params }) {
        const eventService = await app.container.make('akago.event.service');
        const event = eventService.emailPreviewEvents.find((e) => e.constructor.name === params['event-name']);
        if (!event)
            throw AKAPIException.notFound;
        const { data, template } = await event.emailPayload();
        const templateName = AKEmailService.templatePath(template);
        const mjml = edge.render(templateName + '_html.edge', data);
        return mjml;
    }
}
__decorate([
    OpenApiName(`List of events`),
    OpenApiDescription(`An HTML page used for debugging.`),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", Promise)
], AKEventController.prototype, "list", null);
__decorate([
    OpenApiDescription(`Shows a preview of the email associated with the requested event.`),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Function]),
    __metadata("design:returntype", Promise)
], AKEventController.prototype, "previewEmail", null);
//# sourceMappingURL=event_controller.js.map