package email

import (
	"context"
	"fmt"

	"source.gleipnir.technology/Gleipnir/nidus-sync/config"
	"source.gleipnir.technology/Gleipnir/nidus-sync/db"
	modelcomms "source.gleipnir.technology/Gleipnir/nidus-sync/db/gen/nidus-sync/comms/model"
	//"github.com/rs/zerolog/log"
)

func SendReportConfirmation(ctx context.Context, txn db.Ex, contact modelcomms.Contact, destination, report_id string) error {
	err := maybeSendInitialEmail(ctx, txn, contact, destination)
	if err != nil {
		return fmt.Errorf("Failed to handle initial email: %w", err)
	}
	data := make(map[string]string, 0)
	data["report_id"] = report_id
	report_id_str := publicReportID(report_id)
	data["ReportIDStr"] = report_id_str
	data["URLLogo"] = config.MakeURLReport("/static/img/nidus-logo-no-lettering-64.png")
	data["URLReportStatus"] = config.MakeURLReport("/status/%s", report_id)
	data["URLReportUnsubscribe"] = config.MakeURLReport("/email/unsubscribe/report/%s", report_id)
	data["URLUnsubscribe"] = urlUnsubscribe(destination)

	subject := fmt.Sprintf("Mosquito Report Submission - %s", report_id_str)
	return sendEmailBegin(ctx, config.ForwardEmailRMOAddress, destination, templateReportNotificationConfirmationID, subject, data)
}
