package util

import (
	"github.com/gin-gonic/gin"
	"slg/pkg/setting"
)

// GetPage get page parameters
func GetPage(c *gin.Context) int {
	result := 0
	page := ToInt(c.DefaultQuery("page", "1"))
	size := ToInt(c.DefaultQuery("size", "0"))

	if size == 0 {
		size = setting.AppSetting.PageSize
	}
	if page > 0 {
		result = (page - 1) * size
	}

	return result
}

// GetLimit get page parameters
func GetLimit(c *gin.Context) int {
	result := setting.AppSetting.PageSize
	size := ToInt(c.DefaultQuery("size", "0"))
	if size > 0 {
		result = size
	}

	return result
}
