package pagination

import (
	"github.com/gin-gonic/gin"
	"strconv"
)

func GeneratePaginationFromRequest(c *gin.Context) Pagination {
	limit := 2
	page := 1
	sort := "Id desc"
	query := c.Request.URL.Query()
	for key, value := range query {
		queryValue := value[len(value)-1]
		switch key {
		case "limit":
			limit, _ = strconv.Atoi(queryValue)
			break
		case "page":
			page, _ = strconv.Atoi(queryValue)
			break
		case "sort":
			sort = queryValue
			break
		}

	}

	return Pagination{
		Limit: limit,
		Page:  page,
		Sort:  sort,
	}
}
