package infra

import "fmt"

// SSHConfigAddEntry añade un nuevo entry a la lista. Retorna error si el alias
// ya existe. No muta el slice original.
func SSHConfigAddEntry(entries []SSHConfigEntry, entry SSHConfigEntry) ([]SSHConfigEntry, error) {
	for _, e := range entries {
		if e.Alias == entry.Alias {
			return nil, fmt.Errorf("alias %q already exists", entry.Alias)
		}
	}
	result := make([]SSHConfigEntry, len(entries), len(entries)+1)
	copy(result, entries)
	return append(result, entry), nil
}
