// Package db owns the Postgres connection pool wiring and (in later phases)
// sqlc-generated query methods.
package db

import (
	"context"

	"github.com/jackc/pgx/v5/pgxpool"
)

// NewPool constructs a *pgxpool.Pool from the supplied DSN. Connections are
// lazy — NewPool does NOT call Ping (RESEARCH Pitfall 2: lazy is the
// canonical pgxpool behavior; callers exercise the pool via /healthz instead
// of an eager startup ping). Returns an error if the DSN cannot be parsed.
func NewPool(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
	cfg, err := pgxpool.ParseConfig(dsn)
	if err != nil {
		return nil, err
	}
	cfg.MaxConns = 10
	cfg.MinConns = 1
	return pgxpool.NewWithConfig(ctx, cfg)
}
