You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: helpers.go
    path of file: ./repos/porter/internal/repository/gorm/helpers
    
    the code of the file until where you have to start completion: package helpers

import (
	"math"

	"gorm.io/gorm"
)

type PaginatedResult struct {
	NumPages    int64
	CurrentPage int64
	NextPage    int64 `json:"ne
    
func Paginate(db *gorm.DB, pagination *PaginatedResult, opts ...QueryOption) func(db *gorm.DB) *gorm.DB {
	q := Query{
		PageSize: 50,
		Page:     0,
	}

	for _, opt := range opts {
		opt(&q)
	}

	var totalRows int64
	db.Count(&totalRows)

	offset := (q.Page - 1) * q.PageSize

	pagination.NumPages = int64(math.Ceil(float64(totalRows) / float64(q.PageSize)))
	pagination.CurrentPage = int64(q.Page)
	pagination.NextPage = int64(q.Page + 1)
	if pagination.CurrentPage >= pagination.NumPages {
		pagination.NextPage = pagination.NumPages
	}

	return func(db *gorm.DB) *gorm.DB {
		return db.
			Offset(offset).
			Limit(q.PageSize)
	}
}