import { Payload } from 'payload' import type { CollectionConfig, RichTextField } from 'payload' import { Transporter } from 'nodemailer' import {Email, EmailTemplate} from "../payload-types.js" export type BaseEmail = Omit & {template: Omit | TEmailTemplate['id'] | undefined | null} export type BaseEmailTemplate = Omit export type TemplateRendererHook = (template: string, variables: Record) => string | Promise export type TemplateEngine = 'liquidjs' | 'mustache' | 'simple' export interface MailingPluginConfig { collections?: { templates?: string | Partial emails?: string | Partial } defaultFrom?: string defaultFromName?: string transport?: Transporter | MailingTransportConfig queue?: string retryAttempts?: number retryDelay?: number templateRenderer?: TemplateRendererHook templateEngine?: TemplateEngine richTextEditor?: RichTextField['editor'] onReady?: (payload: any) => Promise initOrder?: 'before' | 'after' } export interface MailingTransportConfig { host: string port: number secure?: boolean auth?: { user: string pass: string } } export interface QueuedEmail { id: string template?: string to: string[] cc?: string[] bcc?: string[] from?: string replyTo?: string subject: string html: string text?: string variables?: Record scheduledAt?: string sentAt?: string status: 'pending' | 'processing' | 'sent' | 'failed' attempts: number lastAttemptAt?: string error?: string priority?: number createdAt: string updatedAt: string } // Simple helper type for template variables export interface TemplateVariables { [key: string]: any } export interface MailingService { processEmails(): Promise retryFailedEmails(): Promise renderTemplate(templateSlug: string, variables: TemplateVariables): Promise<{ html: string; text: string; subject: string }> } export interface MailingContext { payload: Payload config: MailingPluginConfig service: MailingService }