package infra

import (
	"fmt"
	"os/exec"
	"strings"
)

// DockerCreateNetwork crea una red Docker con el nombre y driver dados.
// Si el driver está vacío, usa "bridge" por defecto.
// Devuelve el ID de la red creada.
func DockerCreateNetwork(name, driver string) (string, error) {
	if name == "" {
		return "", fmt.Errorf("network name required")
	}
	if driver == "" {
		driver = "bridge"
	}

	out, err := exec.Command("docker", "network", "create", "--driver", driver, name).CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("docker network create %s: %s", name, strings.TrimSpace(string(out)))
	}

	return strings.TrimSpace(string(out)), nil
}
