import SendGridInboundProvider from "./Providers/SendGridInboundProvider";
import { InboundEmailProviderType, InboundEmailProvider as InboundEmailProviderConfig, InboundEmailDomain, InboundEmailWebhookSecret, } from "../../EnvironmentConfig";
import BadDataException from "../../../Types/Exception/BadDataException";
class InboundEmailProviderFactory {
    static getProvider() {
        if (this.instance) {
            return this.instance;
        }
        if (!InboundEmailDomain) {
            throw new BadDataException("Inbound email is not configured. Please set the INBOUND_EMAIL_DOMAIN environment variable.");
        }
        switch (InboundEmailProviderConfig) {
            case InboundEmailProviderType.SendGrid:
                this.instance = new SendGridInboundProvider({
                    inboundDomain: InboundEmailDomain,
                    webhookSecret: InboundEmailWebhookSecret,
                });
                break;
            default:
                throw new BadDataException(`Unknown inbound email provider: ${InboundEmailProviderConfig}`);
        }
        return this.instance;
    }
    /**
     * Check if inbound email is configured
     */
    static isConfigured() {
        return Boolean(InboundEmailDomain);
    }
    /**
     * Generate the email address for a monitor based on its secret key
     */
    static generateMonitorEmailAddress(secretKey) {
        const provider = this.getProvider();
        return provider.generateMonitorEmailAddress(secretKey);
    }
    /**
     * Extract the secret key from an email address
     */
    static extractSecretKeyFromEmail(email) {
        const provider = this.getProvider();
        return provider.extractSecretKeyFromEmail(email);
    }
    /**
     * Get the inbound domain
     */
    static getInboundDomain() {
        return InboundEmailDomain;
    }
    /**
     * Reset the singleton instance (useful for testing)
     */
    static resetInstance() {
        this.instance = null;
    }
}
InboundEmailProviderFactory.instance = null;
export default InboundEmailProviderFactory;
//# sourceMappingURL=InboundEmailProviderFactory.js.map