package util

import (
	"github.com/Unknwon/com"
	"github.com/gin-gonic/gin"

	"bwallet/pkg/setting"
)

// GetPage get page parameters
func GetPage(c *gin.Context) int {
	result := 0
	page := com.StrTo(c.Query("page")).MustInt()

	size := com.StrTo(c.DefaultQuery("size", "0")).MustInt()
	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 := com.StrTo(c.Query("size")).MustInt()
	if size > 0 {
		result = size
	}

	return result
}
