package utils

import (
	smtpmock "github.com/mocktools/go-smtp-mock/v2"
)

var Server smtpmock.Server

// StartMockSMTPServer starts a mock SMTP server for testing
func SMTPStart(host string, port int) error {
	Server = *smtpmock.New(smtpmock.ConfigurationAttr{
		HostAddress:       host,
		PortNumber:        port,
		LogToStdout:       false,
		LogServerActivity: false,
	})
	if err := Server.Start(); err != nil {
		return err
	}
	return nil
}

func SMTPGetMessages() []smtpmock.Message {
	return Server.MessagesAndPurge()
}

func SMTPStop() error {

	if err := Server.Stop(); err != nil {
		return err
	}
	return nil
}
