package notifications

import (
	"context"
	"log"

	"github.com/saveinmed/backend-go/internal/domain"
)

// NotificationService defines the contract for sending alerts.
type NotificationService interface {
	NotifyOrderCreated(ctx context.Context, order *domain.Order, buyer, seller *domain.User) error
	NotifyOrderStatusChanged(ctx context.Context, order *domain.Order, buyer *domain.User) error
}

// LoggerNotificationService prints notifications to stdout for dev/MVP.
type LoggerNotificationService struct{}

func NewLoggerNotificationService() *LoggerNotificationService {
	return &LoggerNotificationService{}
}

func (s *LoggerNotificationService) NotifyOrderCreated(ctx context.Context, order *domain.Order, buyer, seller *domain.User) error {
	log.Printf("📧 [EMAIL] To: Seller <%s>\n   Subject: Novo Pedido #%s recebido!\n   Body: Olá %s, você recebeu um novo pedido de %s. Total: R$ %.2f",
		seller.Email, order.ID, seller.Name, buyer.Name, float64(order.TotalCents)/100)

	log.Printf("📧 [EMAIL] To: Buyer <%s>\n   Subject: Pedido #%s confirmado!\n   Body: Olá %s, seu pedido foi recebido e está aguardando processamento.",
		buyer.Email, order.ID, buyer.Name)

	return nil
}

func (s *LoggerNotificationService) NotifyOrderStatusChanged(ctx context.Context, order *domain.Order, buyer *domain.User) error {
	log.Printf("📧 [EMAIL] To: Buyer <%s>\n   Subject: Atualização do Pedido #%s\n   Body: Olá %s, seu pedido mudou para status: %s.",
		buyer.Email, order.ID, buyer.Name, order.Status)
	return nil
}
