package orchestrator

import (
	"strings"

	"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/agg"
	"github.com/tech/sendico/payments/orchestrator/internal/service/orchestrationv2/xplan"
	paymenttypes "github.com/tech/sendico/pkg/payments/types"
)

func destinationOperationComment(payment *agg.Payment, step xplan.Step) string {
	if step.HopRole != paymenttypes.QuoteRouteHopRoleDestination {
		return ""
	}
	if comment := strings.TrimSpace(step.Comment); comment != "" {
		return comment
	}
	if payment == nil {
		return ""
	}
	return strings.TrimSpace(payment.IntentSnapshot.Comment)
}

func assignDestinationStepComment(stepExecution *agg.StepExecution, payment *agg.Payment, step xplan.Step) {
	if stepExecution == nil {
		return
	}
	stepExecution.Comment = destinationOperationComment(payment, step)
}
