// admin_pagination.go holds shared query-param parsing helpers for the
// operator-facing admin surfaces under /api. They were extracted from PR #2114
// ahead of its split into the request-capture (#2119), connector-event replay
// (#2118), and outbound-delivery (#2116) admin handlers, so those three can be
// implemented concurrently without each redefining the same helper.
package rest

import (
	"time"

	"github.com/gin-gonic/gin"
	"github.com/pingcap-inc/nexuscrm-api-host/requestparams"
)

// parsePositiveLimit reads an optional positive-integer query param `key`,
// defaulting to defaultValue when absent and clamping to maxValue. It writes a
// 400 response and returns ok=false on a non-numeric or non-positive value.
func parsePositiveLimit(c *gin.Context, key string, defaultValue, maxValue int) (int, bool) {
	return requestparams.PositiveLimit(c, key, defaultValue, maxValue)
}

// parseOptionalNonNegativeInt reads an optional non-negative-integer query param
// `key`, defaulting to defaultValue when absent. It writes a 400 response and
// returns ok=false on a non-numeric or negative value.
func parseOptionalNonNegativeInt(c *gin.Context, key string, defaultValue int) (int, bool) {
	return requestparams.OptionalNonNegativeInt(c, key, defaultValue)
}

// parseOptionalRFC3339Nano reads an optional RFC3339Nano timestamp query param
// `key`, returning the zero time when absent. It writes a 400 response and
// returns ok=false on an unparseable value.
func parseOptionalRFC3339Nano(c *gin.Context, key string) (time.Time, bool) {
	return requestparams.OptionalRFC3339Nano(c, key)
}
