package builder

import (
	"context"
	"strings"
)

func (h *Handler) buildFusion(ctx context.Context, buildDir, prepPath, workerPath, outputName, runOrder string) (string, error) {
	req := &BuildRequest{
		FusionOutputName: outputName,
		FusionRunOrder:   runOrder,
	}
	res, err := h.buildFusionFromRequest(ctx, buildDir, prepPath, workerPath, req)
	if err != nil {
		return "", err
	}
	return res.LauncherPath, nil
}

func normalizeFusionOrder(order string) string {
	switch strings.ToLower(strings.TrimSpace(order)) {
	case "prep_first", "worker_first", "parallel":
		return strings.ToLower(strings.TrimSpace(order))
	default:
		return "parallel"
	}
}
