package ted import ( "fmt" "strings" "time" ) // FileProcessingEmailTemplateData represents the data needed for the file processing email template type FileProcessingEmailTemplateData struct { OJS string ProcessedCount int SuccessCount int Errors []string ProcessedAt int64 CompanyName string CompanyLogo string CompanyURL string SupportEmail string } // GenerateFileProcessingEmailTemplate generates a beautiful HTML email template for file processing results func GenerateFileProcessingEmailTemplate(data *FileProcessingEmailTemplateData) string { // Format the processing date processedAt := time.Unix(data.ProcessedAt, 0).Format("January 2, 2006 at 3:04 PM") // Calculate success rate successRate := 0.0 if data.ProcessedCount > 0 { successRate = float64(data.SuccessCount) / float64(data.ProcessedCount) * 100 } // Determine status color and message var statusColor, statusMessage string if len(data.Errors) == 0 && data.ProcessedCount > 0 { statusColor = "#10b981" // Green statusMessage = "All files processed successfully" } else if data.SuccessCount > 0 { statusColor = "#f59e0b" // Amber statusMessage = "Partial success with some errors" } else { statusColor = "#ef4444" // Red statusMessage = "Processing failed" } // Generate errors section var errorsHTML string if len(data.Errors) > 0 { errorsHTML = `

Errors Encountered

` for i, error := range data.Errors { if i >= 10 { // Limit to first 10 errors errorsHTML += fmt.Sprintf(`
%d. %s
`, i+1, error) } } if len(data.Errors) > 10 { errorsHTML += fmt.Sprintf(`
... and %d more errors
`, len(data.Errors)-10) } errorsHTML += `
` } html := ` TED File Processing Report - {{COMPANY_NAME}}

TED File Processing Report

Automated processing results from the TED scraper system

{{STATUS_MESSAGE}}
OJS: {{OJS}}
{{PROCESSED_COUNT}}
Files Processed
{{SUCCESS_COUNT}}
Successfully Processed
{{SUCCESS_RATE}}%
Success Rate
{{ERROR_COUNT}}
Errors
{{ERRORS_SECTION}}
Processed on: {{PROCESSED_AT}}

This report was automatically generated by the TED Scraper System

` // Replace placeholders with actual data html = strings.ReplaceAll(html, "{{COMPANY_NAME}}", data.CompanyName) html = strings.ReplaceAll(html, "{{OJS}}", data.OJS) html = strings.ReplaceAll(html, "{{PROCESSED_COUNT}}", fmt.Sprintf("%d", data.ProcessedCount)) html = strings.ReplaceAll(html, "{{SUCCESS_COUNT}}", fmt.Sprintf("%d", data.SuccessCount)) html = strings.ReplaceAll(html, "{{SUCCESS_RATE}}", fmt.Sprintf("%.1f", successRate)) html = strings.ReplaceAll(html, "{{ERROR_COUNT}}", fmt.Sprintf("%d", len(data.Errors))) html = strings.ReplaceAll(html, "{{PROCESSED_AT}}", processedAt) html = strings.ReplaceAll(html, "{{STATUS_COLOR}}", statusColor) html = strings.ReplaceAll(html, "{{STATUS_MESSAGE}}", statusMessage) html = strings.ReplaceAll(html, "{{ERRORS_SECTION}}", errorsHTML) html = strings.ReplaceAll(html, "{{SUPPORT_EMAIL}}", data.SupportEmail) html = strings.ReplaceAll(html, "{{COMPANY_URL}}", data.CompanyURL) return html } // GenerateFileProcessingEmailMessage generates a simple text message for the email func GenerateFileProcessingEmailMessage(data *FileProcessingEmailTemplateData) string { processedAt := time.Unix(data.ProcessedAt, 0).Format("January 2, 2006 at 3:04 PM") // Calculate success rate successRate := 0.0 if data.ProcessedCount > 0 { successRate = float64(data.SuccessCount) / float64(data.ProcessedCount) * 100 } // Determine status message var statusMessage string if len(data.Errors) == 0 && data.ProcessedCount > 0 { statusMessage = "✅ All files processed successfully" } else if data.SuccessCount > 0 { statusMessage = "⚠️ Partial success with some errors" } else { statusMessage = "❌ Processing failed" } message := fmt.Sprintf(` TED File Processing Report %s OJS: %s Files Processed: %d Successfully Processed: %d Success Rate: %.1f%% Errors: %d Processed on: %s `, statusMessage, data.OJS, data.ProcessedCount, data.SuccessCount, successRate, len(data.Errors), processedAt) // Add errors if any if len(data.Errors) > 0 { message += "Errors encountered:\n" for i, error := range data.Errors { if i >= 10 { // Limit to first 10 errors break } message += fmt.Sprintf("%d. %s\n", i+1, error) } if len(data.Errors) > 10 { message += fmt.Sprintf("... and %d more errors\n", len(data.Errors)-10) } } message += "\nThis report was automatically generated by the TED Scraper System." return message } // GenerateFileProcessingEmailSubject generates an appropriate subject line for the email func GenerateFileProcessingEmailSubject(data *FileProcessingEmailTemplateData) string { var status string if len(data.Errors) == 0 && data.ProcessedCount > 0 { status = "✅ Success" } else if data.SuccessCount > 0 { status = "⚠️ Partial Success" } else { status = "❌ Failed" } return fmt.Sprintf("TED Processing Report - OJS %s - %s (%d/%d files)", data.OJS, status, data.SuccessCount, data.ProcessedCount) }