//
// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.
//

package email

import (
	"fmt"

	"github.com/veypi/vbase/models"
)

// Provider 邮件提供商接口
type Provider interface {
	Send(to, subject, content string) error
}

// NewProvider 创建邮件提供商
func NewProvider() (Provider, error) {
	// 从数据库获取配置
	enabled, err := models.GetSettingBool(models.SettingEmailEnabled)
	if err != nil || !enabled {
		return nil, fmt.Errorf("email service not enabled")
	}

	providerType, _ := models.GetSetting(models.SettingEmailProvider)
	switch providerType {
	case "smtp":
		return NewSMTPProvider()
	default:
		return NewSMTPProvider() // 默认使用 SMTP
	}
}
