func (em Emitter) chooseOutputFiles(tfs []TemplatedFile) []string {
	seenBaseNames := make(map[string]struct{}, len(tfs))
	hasBaseCollision := false
	for _, tf := range tfs {
		base := filepath.Base(tf.SourcePath)
		if _, ok := seenBaseNames[base]; ok {
			hasBaseCollision = true
		}
		seenBaseNames[base] = struct{}{}
	}
	if !hasBaseCollision {
		outNames := make([]string, len(tfs))
		for i, tf := range tfs {
			out := filepath.Base(tf.SourcePath)
			out += ".go"
			outNames[i] = out
		}
		return outNames
	}
	outNames := make([]string, len(tfs))  
	usedNames := make(map[string]int)     
	firstIdx := make(map[string]int)      
	for i, tf := range tfs {
		out := filepath.Base(tf.SourcePath)
		parent := filepath.Base(filepath.Dir(tf.SourcePath))
		out = parent + "_" + out
		n, ok := usedNames[out]
		usedNames[out] = n + 1
		if ok {
			firstI := firstIdx[out]
			outNames[i] = out + "." + strconv.Itoa(n)
			if n == 1 {
				outNames[firstI] += ".0"
			}
		} else {
			outNames[i] = out
			firstIdx[out] = i
		}
	}
	for i := range outNames {
		outNames[i] += ".go"
	}
	return outNames
}
chooseOutputFiles returns the output paths to use for each TemplatedFile.
Necessary for cases like "alpha/query.sql" and "bravo/query.sql" where
we can't simply use "query.sql.go".
package golang
import (
	"fmt"
	"github.com/jschaf/pggen/internal/errs"
	"os"
	"path/filepath"
	"strconv"
	"text/template"
)
type Emitter struct {
	outDir string
	tmpl   *template.Template
}
func NewEmitter(outDir string, tmpl *template.Template) Emitter {
	return Emitter{outDir: outDir, tmpl: tmpl}
}
func (em Emitter) EmitAllQueryFiles(tfs []TemplatedFile) (mErr error) {
	outs := em.chooseOutputFiles(tfs)
	for i, tf := range tfs {
		if err := em.emitQueryFile(outs[i], tf); err != nil {
			return err
		}
	}
	return nil
}