package analytics

import (
	"context"

	"github.com/nexuscrm/shared/pkg/queryspec"
)

// WithAggregateFetchLimit asks aggregate query execution to fetch enough
// grouped rows for a caller-owned result window before the caller slices a
// physical page out of that window, or to fetch a one-row sentinel when the
// caller needs to detect that a grouped result would exceed one REST batch.
func WithAggregateFetchLimit(ctx context.Context, limit int) context.Context {
	return queryspec.WithAggregateFetchLimit(ctx, limit)
}

// AggregateFetchLimitFromContext returns the aggregate fetch limit requested by
// WithAggregateFetchLimit. It is exported so REST-layer tests can assert the
// cross-package contract without reaching into unexported query service state.
func AggregateFetchLimitFromContext(ctx context.Context) int {
	return queryspec.AggregateFetchLimitFromContext(ctx)
}
