package helpers

import (
	dto "astrology-api/dto_astrologer/activity"
	"strconv"

	"github.com/gin-gonic/gin"
)

//////////////////////////////////////////////////////////////
// Get Pagination Request
//////////////////////////////////////////////////////////////

func GetPaginationRequest(
	ctx *gin.Context,
) dto.PaginationRequest {

	page := 1
	limit := 10

	//------------------------------------------
	// Page
	//------------------------------------------

	if value := ctx.Query("page"); value != "" {

		if parsed, err := strconv.Atoi(value); err == nil && parsed > 0 {

			page = parsed
		}
	}

	//------------------------------------------
	// Limit
	//------------------------------------------

	if value := ctx.Query("limit"); value != "" {

		if parsed, err := strconv.Atoi(value); err == nil && parsed > 0 {

			limit = parsed
		}
	}

	//------------------------------------------
	// Return DTO
	//------------------------------------------

	return dto.PaginationRequest{

		Page: page,

		Limit: limit,

		Search: ctx.DefaultQuery("search", ""),

		Status: ctx.DefaultQuery("status", "ALL"),
	}
}
