"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContactEmailService = void 0;
const EmailService_1 = require("./EmailService");
const ContactAggregate_1 = require("../../Domain/Contact/ContactAggregate");
const Logger_1 = require("./Logger");
const EmailTemplateHelper_1 = require("./EmailTemplateHelper");
class ContactEmailService {
    constructor(contactRepo) {
        this.contactRepo = contactRepo;
        this.emailService = new EmailService_1.EmailService();
    }
    async sendResponse(responseData) {
        try {
            // First update the contact with the response
            await this.contactRepo.update(responseData.contactId, {
                adminResponse: responseData.message,
                responseDate: new Date(),
                respondedBy: responseData.adminUserId,
            });
            // Determine language and template
            const language = responseData.language || 'en';
            const templateName = language === 'en' ? 'contact-response' : `contact-response-${language}`;
            // Prepare template data
            const templateData = {
                contactName: responseData.contactName,
                contactTypeString: this.getContactTypeString(responseData.contactType, language),
                contactTypeBadge: this.getContactTypeBadge(responseData.contactType),
                originalMessage: responseData.originalMessage,
                adminResponse: responseData.message,
                companyName: 'SerpentRace',
                supportEmail: 'support@serpentrace.com'
            };
            // Send email using EmailService with template
            const emailSent = await this.emailService.sendEmail({
                to: responseData.to,
                subject: this.getLocalizedContactResponseSubject(language),
                template: templateName,
                templateData
            });
            if (emailSent) {
                (0, Logger_1.logOther)('Contact response email sent successfully', {
                    to: responseData.to,
                    subject: this.getLocalizedContactResponseSubject(language),
                    contactId: responseData.contactId,
                    respondedBy: responseData.adminUserId,
                    language
                });
            }
            else {
                throw new Error('Email service failed to send email');
            }
        }
        catch (error) {
            (0, Logger_1.logError)('Failed to send contact response email', error instanceof Error ? error : new Error(String(error)));
            throw new Error('Failed to send email response');
        }
    }
    getLocalizedContactResponseSubject(language) {
        const subjects = {
            contactResponse: {
                en: 'SerpentRace - Response to Your Message',
                hu: 'SerpentRace - Válasz az üzenetére',
                de: 'SerpentRace - Antwort auf Ihre Nachricht'
            }
        };
        return EmailTemplateHelper_1.EmailTemplateHelper.getLocalizedSubject('contactResponse', subjects, language);
    }
    getContactTypeString(type, language = 'en') {
        const translations = {
            [ContactAggregate_1.ContactType.BUG]: {
                en: 'Bug Report',
                hu: 'Hiba bejelentés',
                de: 'Fehlerbericht'
            },
            [ContactAggregate_1.ContactType.PROBLEM]: {
                en: 'Problem',
                hu: 'Probléma',
                de: 'Problem'
            },
            [ContactAggregate_1.ContactType.QUESTION]: {
                en: 'Question',
                hu: 'Kérdés',
                de: 'Frage'
            },
            [ContactAggregate_1.ContactType.SALES]: {
                en: 'Sales Inquiry',
                hu: 'Értékesítési kérdés',
                de: 'Verkaufsanfrage'
            },
            [ContactAggregate_1.ContactType.OTHER]: {
                en: 'General Inquiry',
                hu: 'Általános kérdés',
                de: 'Allgemeine Anfrage'
            }
        };
        return translations[type]?.[language] || translations[type]?.['en'] || 'Contact';
    }
    getContactTypeBadge(type) {
        switch (type) {
            case ContactAggregate_1.ContactType.BUG:
                return 'bug';
            case ContactAggregate_1.ContactType.PROBLEM:
                return 'problem';
            case ContactAggregate_1.ContactType.QUESTION:
                return 'question';
            case ContactAggregate_1.ContactType.SALES:
                return 'sales';
            case ContactAggregate_1.ContactType.OTHER:
                return 'other';
            default:
                return 'other';
        }
    }
}
exports.ContactEmailService = ContactEmailService;
//# sourceMappingURL=ContactEmailService.js.map