package contacts

import (
	"context"

	"github.com/ultisuite/ulti-backend/internal/automation"
	"github.com/ultisuite/ulti-backend/internal/mail/rules"
	"github.com/ultisuite/ulti-backend/internal/nextcloud"
)

type contactAutomation interface {
	OnContactEvent(ctx context.Context, externalUserID string, trigger rules.TriggerType, payload automation.ContactPayload)
}

func (h *Handler) SetAutomation(d contactAutomation) {
	h.automation = d
}

func contactPayloadFrom(bookID string, contact *nextcloud.Contact) automation.ContactPayload {
	if contact == nil {
		return automation.ContactPayload{BookID: bookID}
	}
	return automation.ContactPayload{
		ID:     contact.UID,
		BookID: bookID,
		Name:   contact.FullName,
		Email:  contact.Email,
		Phone:  contact.Phone,
		Org:    contact.Org,
	}
}
