package mailimp

import (
	"github.com/tech/sendico/notification/interface/api/localizer"
	"github.com/tech/sendico/pkg/domainprovider"
)

type MessageImp struct {
	templateID    string
	accountUID    string
	locale        string
	recipients    []string
	recipientName string
	buttonLink    string
	parameters    map[string]any
}

func (m *MessageImp) TemplateID() string {
	return m.templateID
}

func (m *MessageImp) Locale() string {
	return m.locale
}

func (m *MessageImp) AccountID() string {
	return m.accountUID
}

func (m *MessageImp) Recipients() []string {
	return m.recipients
}

func (m *MessageImp) Parameters() map[string]any {
	return m.parameters
}

func (m *MessageImp) Body(l localizer.Localizer, dp domainprovider.DomainProvider) (string, error) {
	if len(m.buttonLink) == 0 {
		return NewEmailNotification(l, dp).Build(m)
	}
	page := NewOneButton(l, dp)
	buttonLabel, err := l.LocalizeString("btn."+m.TemplateID(), m.Locale())
	if err != nil {
		return "", err
	}
	page.AddButton(buttonLabel, m.buttonLink)
	return page.Build(m)
}

func createMessageImp() *MessageImp {
	return &MessageImp{
		parameters: map[string]any{},
		recipients: []string{},
	}
}
