package runtime

import "nest/src/catalog"

// BuildRunArgs assembles the container invocation per AGENTS.md §4.4: nest's
// defaults first, then the tool's container options so they win on conflict,
// then image, command, and tool arguments.
func BuildRunArgs(image, command, toolName, persistenceDir string, opts *catalog.Container, tty bool, toolArgs []string) []string {
	args := []string{"run", "--rm", "-i"}
	if tty {
		args = append(args, "-t")
	}
	args = append(args,
		"--label", ManagedLabel,
		"--label", ToolLabel+"="+toolName,
		"-v", persistenceDir+":/persistence",
		"--workdir", "/persistence",
	)
	if opts != nil {
		if opts.Network != "" {
			args = append(args, "--network", opts.Network)
		}
		for _, cap := range opts.CapAdd {
			args = append(args, "--cap-add", cap)
		}
		args = append(args, opts.ExtraArgs...)
	}
	args = append(args, image, command)
	return append(args, toolArgs...)
}
