package requests

import "github.com/samber/lo"

type Pager struct {
	Pagination `json:",inline"`
	Total      int64 `json:"total"`
	Items      any   `json:"items"`
}

type Pagination struct {
	Page   int64 `json:"page" form:"page" query:"page"`
	Limit  int64 `json:"limit" form:"limit" query:"limit"`
	Offset int64 `json:"-"`
}

func (filter *Pagination) Format() {
	if filter.Page <= 0 {
		filter.Page = 1
	}

	if !lo.Contains([]int64{10, 25, 50, 100}, filter.Limit) {
		filter.Limit = 10
	}

	filter.Offset = (filter.Page - 1) * filter.Limit
}
