"use strict";
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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmailTemplateController = void 0;
const openapi = require("@nestjs/swagger");
const common_1 = require("@nestjs/common");
const platform_express_1 = require("@nestjs/platform-express");
const swagger_1 = require("@nestjs/swagger");
const create_email_template_dto_1 = require("../dtos/create-email-template.dto");
const update_email_template_dto_1 = require("../dtos/update-email-template.dto");
const email_template_service_1 = require("../services/email-template.service");
const setting_service_1 = require("../services/setting.service");
const Mailgen = require("mailgen");
let EmailTemplateController = class EmailTemplateController {
    constructor(service, settingService) {
        this.service = service;
        this.settingService = settingService;
    }
    create(createDto, files) {
        return this.service.create(createDto, files);
    }
    insertMany(createDtos, filesArray = []) {
        return this.service.insertMany(createDtos, filesArray);
    }
    update(id, updateDto, files) {
        return this.service.update(id, updateDto, files);
    }
    async findMany(query) {
        return this.service.find(query);
    }
    async findOne(id, query) {
        return this.service.findOne(+id, query);
    }
    async deleteMany(ids) {
        return this.service.deleteMany(ids);
    }
    async delete(id) {
        return this.service.delete(id);
    }
    generateMailgenTemplate(templateType) {
        const appName = this.settingService.getConfigValue('appTitle');
        const appUrl = this.settingService.getConfigValue('solidAppWebsiteUrl');
        var mailGenerator = new Mailgen({
            theme: 'default',
            product: {
                name: appName,
                link: appUrl
            }
        });
        let email = null;
        if (templateType === 'otp-on-register') {
            email = {
                body: {
                    name: 'John Appleseed',
                    intro: `Welcome to ${appName}! We\'re very excited to have you on board.`,
                    action: {
                        instructions: `To get started with ${appName}, please verify your account using the below verification code.`,
                        button: {
                            color: '#22BC66',
                            text: `321455`,
                            link: null
                        }
                    },
                    outro: 'Need help, or have questions? Just reply to this email, we\'d love to help.'
                }
            };
        }
        if (templateType === 'otp-on-login') {
            email = {
                body: {
                    name: 'John Appleseed',
                    intro: `Welcome to ${appName}!`,
                    action: {
                        instructions: `Login to ${appName}, using the below verification code.`,
                        button: {
                            color: '#22BC66',
                            text: `321455`,
                            link: null
                        }
                    },
                    outro: 'Need help, or have questions? Just reply to this email, we\'d love to help.'
                }
            };
        }
        if (templateType === 'forgot-password') {
            email = {
                body: {
                    name: 'John Appleseed',
                    intro: `Welcome to ${appName}!`,
                    action: {
                        instructions: `Click on the below link to reset your password. Please note that this link will expire in 10 minutes.`,
                        button: {
                            color: '#22BC66',
                            text: `Reset Password`,
                            link: `https://example.com`
                        }
                    },
                    outro: 'Need help, or have questions? Just reply to this email, we\'d love to help.'
                }
            };
        }
        var emailBody = mailGenerator.generate(email);
        return emailBody;
    }
};
exports.EmailTemplateController = EmailTemplateController;
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Post)(),
    (0, common_1.UseInterceptors)((0, platform_express_1.AnyFilesInterceptor)()),
    openapi.ApiResponse({ status: 201, type: require("../entities/email-template.entity").EmailTemplate }),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.UploadedFiles)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [create_email_template_dto_1.CreateEmailTemplateDto, Array]),
    __metadata("design:returntype", void 0)
], EmailTemplateController.prototype, "create", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Post)('/bulk'),
    (0, common_1.UseInterceptors)((0, platform_express_1.AnyFilesInterceptor)()),
    openapi.ApiResponse({ status: 201, type: [require("../entities/email-template.entity").EmailTemplate] }),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.UploadedFiles)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Array, Array]),
    __metadata("design:returntype", void 0)
], EmailTemplateController.prototype, "insertMany", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Put)(':id'),
    (0, common_1.UseInterceptors)((0, platform_express_1.AnyFilesInterceptor)()),
    openapi.ApiResponse({ status: 200, type: require("../entities/email-template.entity").EmailTemplate }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, common_1.UploadedFiles)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, update_email_template_dto_1.UpdateEmailTemplateDto, Array]),
    __metadata("design:returntype", void 0)
], EmailTemplateController.prototype, "update", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, swagger_1.ApiQuery)({ name: 'showSoftDeleted', required: false, type: Boolean }),
    (0, swagger_1.ApiQuery)({ name: 'showOnlySoftDeleted', required: false, type: Boolean }),
    (0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }),
    (0, swagger_1.ApiQuery)({ name: 'offset', required: false, type: Number }),
    (0, swagger_1.ApiQuery)({ name: 'fields', required: false, type: Array }),
    (0, swagger_1.ApiQuery)({ name: 'sort', required: false, type: Array }),
    (0, swagger_1.ApiQuery)({ name: 'groupBy', required: false, type: Array }),
    (0, swagger_1.ApiQuery)({ name: 'populate', required: false, type: Array }),
    (0, swagger_1.ApiQuery)({ name: 'populateMedia', required: false, type: Array }),
    (0, swagger_1.ApiQuery)({ name: 'filters', required: false, type: Array }),
    (0, common_1.Get)(),
    openapi.ApiResponse({ status: 200, type: Object }),
    __param(0, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], EmailTemplateController.prototype, "findMany", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Get)(':id'),
    openapi.ApiResponse({ status: 200, type: require("../entities/email-template.entity").EmailTemplate }),
    __param(0, (0, common_1.Param)('id')),
    __param(1, (0, common_1.Query)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, Object]),
    __metadata("design:returntype", Promise)
], EmailTemplateController.prototype, "findOne", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Delete)('/bulk'),
    openapi.ApiResponse({ status: 200, type: Object }),
    __param(0, (0, common_1.Body)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Array]),
    __metadata("design:returntype", Promise)
], EmailTemplateController.prototype, "deleteMany", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Delete)(':id'),
    openapi.ApiResponse({ status: 200, type: require("../entities/email-template.entity").EmailTemplate }),
    __param(0, (0, common_1.Param)('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number]),
    __metadata("design:returntype", Promise)
], EmailTemplateController.prototype, "delete", null);
__decorate([
    (0, swagger_1.ApiBearerAuth)("jwt"),
    (0, common_1.Get)('mailgen-template/:templateType'),
    (0, common_1.Header)('content-type', 'text/html'),
    openapi.ApiResponse({ status: 200, type: Object }),
    __param(0, (0, common_1.Param)('templateType')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", void 0)
], EmailTemplateController.prototype, "generateMailgenTemplate", null);
exports.EmailTemplateController = EmailTemplateController = __decorate([
    (0, common_1.Controller)('email-template'),
    (0, swagger_1.ApiTags)("Solid Core"),
    __metadata("design:paramtypes", [email_template_service_1.EmailTemplateService,
        setting_service_1.SettingService])
], EmailTemplateController);
//# sourceMappingURL=email-template.controller.js.map