import { ResendProvider } from "./providers/resend";
import { ConsoleProvider } from "./providers/console";
class EmailFactory {
  static instance = null;
  static create(options = {}) {
    const {
      provider = "auto",
      resendApiKey = process.env.RESEND_API_KEY,
      defaultFrom,
      consoleOptions
    } = options;
    if (this.instance && provider === "auto") {
      return this.instance;
    }
    let selectedProvider;
    if (provider === "console") {
      selectedProvider = new ConsoleProvider(consoleOptions);
    } else if (provider === "resend") {
      if (!resendApiKey) {
        throw new Error("Resend API key is required when using Resend provider");
      }
      selectedProvider = new ResendProvider(resendApiKey, defaultFrom);
    } else {
      if (process.env.NODE_ENV === "development" && !process.env.FORCE_RESEND_IN_DEV) {
        console.log("\u{1F4E7} Using Console email provider (development mode)");
        selectedProvider = new ConsoleProvider({
          logLevel: process.env.EMAIL_LOG_LEVEL || "summary",
          ...consoleOptions
        });
      } else if (resendApiKey) {
        selectedProvider = new ResendProvider(resendApiKey, defaultFrom);
      } else {
        if (process.env.NODE_ENV === "production") {
          throw new Error("Email provider API key is required in production");
        }
        console.warn("\u26A0\uFE0F No email API key found, using Console provider as fallback");
        selectedProvider = new ConsoleProvider(consoleOptions);
      }
    }
    this.instance = selectedProvider;
    return selectedProvider;
  }
  static getInstance() {
    if (!this.instance) {
      this.instance = this.create();
    }
    return this.instance;
  }
  static reset() {
    this.instance = null;
  }
}
export {
  EmailFactory
};
