import type { Result } from "@pkg/result";
import { z } from "zod";

export interface EmailServiceProvider {
  initialize(): Result<boolean>;
  sendEmail(payload: EmailPayload): Promise<Result<boolean>>;
  sendEmailWithReact(payload: {
    to: string;
    subject: string;
    from: string;
    cc?: string[];
    bcc?: string[];
    attachments?: any[];
    template: string;
    templateData: any;
  }): Promise<Result<boolean>>;
}

export const EmailProviders = {
  Resend: "Resend",
  SendGrid: "SendGrid",
} as const;
export type EmailProviderTypes = keyof typeof EmailProviders;

export const emailConfigModel = z.object({
  provider: z.string(),
  config: z.object({
    apiKey: z.string(),
  }),
});
export type EmailConfig = z.infer<typeof emailConfigModel>;

export const emailPayloadModel = z.object({
  to: z.string().email(),
  subject: z.string(),
  from: z.string().email().optional(),
  cc: z.array(z.string().email()).optional(),
  bcc: z.array(z.string().email()).optional(),
  attachments: z.array(z.any()).optional(),
  html: z.string().optional(),
  text: z.string().optional(),
  react: z.any(),
});
export type EmailPayload = z.infer<typeof emailPayloadModel>;
