package svc

import (
	"juwan-backend/app/email/mq/internal/config"
	"juwan-backend/app/email/mq/internal/mailer"

	"github.com/zeromicro/go-zero/core/logx"
)

type ServiceContext struct {
	c          config.Config
	MailSender *mailer.Sender
}

func NewServiceContext(c config.Config) *ServiceContext {
	var sender *mailer.Sender
	if c.Mail.Enabled {
		mailSender, err := mailer.NewSender(c.Mail)
		if err != nil {
			logx.Errorf("failed to init mail sender: %v", err)
		} else {
			sender = mailSender
		}
	}

	return &ServiceContext{
		c:          c,
		MailSender: sender,
	}
}
