// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"fmt"
	"wechat-api/ent/agent"
	"wechat-api/ent/agentbase"
	"wechat-api/ent/aliyunavatar"
	"wechat-api/ent/allocagent"
	"wechat-api/ent/apikey"
	"wechat-api/ent/batchmsg"
	"wechat-api/ent/category"
	"wechat-api/ent/chatrecords"
	"wechat-api/ent/chatsession"
	"wechat-api/ent/contact"
	"wechat-api/ent/creditbalance"
	"wechat-api/ent/creditusage"
	"wechat-api/ent/employee"
	"wechat-api/ent/employeeconfig"
	"wechat-api/ent/label"
	"wechat-api/ent/labelrelationship"
	"wechat-api/ent/labeltagging"
	"wechat-api/ent/message"
	"wechat-api/ent/messagerecords"
	"wechat-api/ent/msg"
	"wechat-api/ent/payrecharge"
	"wechat-api/ent/server"
	"wechat-api/ent/sopnode"
	"wechat-api/ent/sopstage"
	"wechat-api/ent/soptask"
	"wechat-api/ent/token"
	"wechat-api/ent/tutorial"
	"wechat-api/ent/usagedetail"
	"wechat-api/ent/usagestatisticday"
	"wechat-api/ent/usagestatistichour"
	"wechat-api/ent/usagestatisticmonth"
	"wechat-api/ent/usagetotal"
	"wechat-api/ent/whatsapp"
	"wechat-api/ent/whatsappchannel"
	"wechat-api/ent/workexperience"
	"wechat-api/ent/wpchatroom"
	"wechat-api/ent/wpchatroommember"
	"wechat-api/ent/wx"
	"wechat-api/ent/wxcard"
	"wechat-api/ent/wxcarduser"
	"wechat-api/ent/wxcardvisit"
	"wechat-api/ent/xunji"
)

const errInvalidPage = "INVALID_PAGE"

const (
	listField     = "list"
	pageNumField  = "pageNum"
	pageSizeField = "pageSize"
)

type PageDetails struct {
	Page  uint64 `json:"page"`
	Size  uint64 `json:"size"`
	Total uint64 `json:"total"`
}

// OrderDirection defines the directions in which to order a list of items.
type OrderDirection string

const (
	// OrderDirectionAsc specifies an ascending order.
	OrderDirectionAsc OrderDirection = "ASC"
	// OrderDirectionDesc specifies a descending order.
	OrderDirectionDesc OrderDirection = "DESC"
)

// Validate the order direction value.
func (o OrderDirection) Validate() error {
	if o != OrderDirectionAsc && o != OrderDirectionDesc {
		return fmt.Errorf("%s is not a valid OrderDirection", o)
	}
	return nil
}

// String implements fmt.Stringer interface.
func (o OrderDirection) String() string {
	return string(o)
}

func (o OrderDirection) reverse() OrderDirection {
	if o == OrderDirectionDesc {
		return OrderDirectionAsc
	}
	return OrderDirectionDesc
}

const errInvalidPagination = "INVALID_PAGINATION"

type AgentPager struct {
	Order  agent.OrderOption
	Filter func(*AgentQuery) (*AgentQuery, error)
}

// AgentPaginateOption enables pagination customization.
type AgentPaginateOption func(*AgentPager)

// DefaultAgentOrder is the default ordering of Agent.
var DefaultAgentOrder = Desc(agent.FieldID)

func newAgentPager(opts []AgentPaginateOption) (*AgentPager, error) {
	pager := &AgentPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultAgentOrder
	}
	return pager, nil
}

func (p *AgentPager) ApplyFilter(query *AgentQuery) (*AgentQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// AgentPageList is Agent PageList result.
type AgentPageList struct {
	List        []*Agent     `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (a *AgentQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentPaginateOption,
) (*AgentPageList, error) {

	pager, err := newAgentPager(opts)
	if err != nil {
		return nil, err
	}

	if a, err = pager.ApplyFilter(a); err != nil {
		return nil, err
	}

	ret := &AgentPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := a.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		a = a.Order(pager.Order)
	} else {
		a = a.Order(DefaultAgentOrder)
	}

	a = a.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := a.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type AgentBasePager struct {
	Order  agentbase.OrderOption
	Filter func(*AgentBaseQuery) (*AgentBaseQuery, error)
}

// AgentBasePaginateOption enables pagination customization.
type AgentBasePaginateOption func(*AgentBasePager)

// DefaultAgentBaseOrder is the default ordering of AgentBase.
var DefaultAgentBaseOrder = Desc(agentbase.FieldID)

func newAgentBasePager(opts []AgentBasePaginateOption) (*AgentBasePager, error) {
	pager := &AgentBasePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultAgentBaseOrder
	}
	return pager, nil
}

func (p *AgentBasePager) ApplyFilter(query *AgentBaseQuery) (*AgentBaseQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// AgentBasePageList is AgentBase PageList result.
type AgentBasePageList struct {
	List        []*AgentBase `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (ab *AgentBaseQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...AgentBasePaginateOption,
) (*AgentBasePageList, error) {

	pager, err := newAgentBasePager(opts)
	if err != nil {
		return nil, err
	}

	if ab, err = pager.ApplyFilter(ab); err != nil {
		return nil, err
	}

	ret := &AgentBasePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ab.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ab = ab.Order(pager.Order)
	} else {
		ab = ab.Order(DefaultAgentBaseOrder)
	}

	ab = ab.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ab.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type AliyunAvatarPager struct {
	Order  aliyunavatar.OrderOption
	Filter func(*AliyunAvatarQuery) (*AliyunAvatarQuery, error)
}

// AliyunAvatarPaginateOption enables pagination customization.
type AliyunAvatarPaginateOption func(*AliyunAvatarPager)

// DefaultAliyunAvatarOrder is the default ordering of AliyunAvatar.
var DefaultAliyunAvatarOrder = Desc(aliyunavatar.FieldID)

func newAliyunAvatarPager(opts []AliyunAvatarPaginateOption) (*AliyunAvatarPager, error) {
	pager := &AliyunAvatarPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultAliyunAvatarOrder
	}
	return pager, nil
}

func (p *AliyunAvatarPager) ApplyFilter(query *AliyunAvatarQuery) (*AliyunAvatarQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// AliyunAvatarPageList is AliyunAvatar PageList result.
type AliyunAvatarPageList struct {
	List        []*AliyunAvatar `json:"list"`
	PageDetails *PageDetails    `json:"pageDetails"`
}

func (aa *AliyunAvatarQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...AliyunAvatarPaginateOption,
) (*AliyunAvatarPageList, error) {

	pager, err := newAliyunAvatarPager(opts)
	if err != nil {
		return nil, err
	}

	if aa, err = pager.ApplyFilter(aa); err != nil {
		return nil, err
	}

	ret := &AliyunAvatarPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := aa.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		aa = aa.Order(pager.Order)
	} else {
		aa = aa.Order(DefaultAliyunAvatarOrder)
	}

	aa = aa.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := aa.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type AllocAgentPager struct {
	Order  allocagent.OrderOption
	Filter func(*AllocAgentQuery) (*AllocAgentQuery, error)
}

// AllocAgentPaginateOption enables pagination customization.
type AllocAgentPaginateOption func(*AllocAgentPager)

// DefaultAllocAgentOrder is the default ordering of AllocAgent.
var DefaultAllocAgentOrder = Desc(allocagent.FieldID)

func newAllocAgentPager(opts []AllocAgentPaginateOption) (*AllocAgentPager, error) {
	pager := &AllocAgentPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultAllocAgentOrder
	}
	return pager, nil
}

func (p *AllocAgentPager) ApplyFilter(query *AllocAgentQuery) (*AllocAgentQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// AllocAgentPageList is AllocAgent PageList result.
type AllocAgentPageList struct {
	List        []*AllocAgent `json:"list"`
	PageDetails *PageDetails  `json:"pageDetails"`
}

func (aa *AllocAgentQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...AllocAgentPaginateOption,
) (*AllocAgentPageList, error) {

	pager, err := newAllocAgentPager(opts)
	if err != nil {
		return nil, err
	}

	if aa, err = pager.ApplyFilter(aa); err != nil {
		return nil, err
	}

	ret := &AllocAgentPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := aa.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		aa = aa.Order(pager.Order)
	} else {
		aa = aa.Order(DefaultAllocAgentOrder)
	}

	aa = aa.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := aa.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type ApiKeyPager struct {
	Order  apikey.OrderOption
	Filter func(*ApiKeyQuery) (*ApiKeyQuery, error)
}

// ApiKeyPaginateOption enables pagination customization.
type ApiKeyPaginateOption func(*ApiKeyPager)

// DefaultApiKeyOrder is the default ordering of ApiKey.
var DefaultApiKeyOrder = Desc(apikey.FieldID)

func newApiKeyPager(opts []ApiKeyPaginateOption) (*ApiKeyPager, error) {
	pager := &ApiKeyPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultApiKeyOrder
	}
	return pager, nil
}

func (p *ApiKeyPager) ApplyFilter(query *ApiKeyQuery) (*ApiKeyQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// ApiKeyPageList is ApiKey PageList result.
type ApiKeyPageList struct {
	List        []*ApiKey    `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (ak *ApiKeyQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...ApiKeyPaginateOption,
) (*ApiKeyPageList, error) {

	pager, err := newApiKeyPager(opts)
	if err != nil {
		return nil, err
	}

	if ak, err = pager.ApplyFilter(ak); err != nil {
		return nil, err
	}

	ret := &ApiKeyPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ak.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ak = ak.Order(pager.Order)
	} else {
		ak = ak.Order(DefaultApiKeyOrder)
	}

	ak = ak.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ak.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type BatchMsgPager struct {
	Order  batchmsg.OrderOption
	Filter func(*BatchMsgQuery) (*BatchMsgQuery, error)
}

// BatchMsgPaginateOption enables pagination customization.
type BatchMsgPaginateOption func(*BatchMsgPager)

// DefaultBatchMsgOrder is the default ordering of BatchMsg.
var DefaultBatchMsgOrder = Desc(batchmsg.FieldID)

func newBatchMsgPager(opts []BatchMsgPaginateOption) (*BatchMsgPager, error) {
	pager := &BatchMsgPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultBatchMsgOrder
	}
	return pager, nil
}

func (p *BatchMsgPager) ApplyFilter(query *BatchMsgQuery) (*BatchMsgQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// BatchMsgPageList is BatchMsg PageList result.
type BatchMsgPageList struct {
	List        []*BatchMsg  `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (bm *BatchMsgQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...BatchMsgPaginateOption,
) (*BatchMsgPageList, error) {

	pager, err := newBatchMsgPager(opts)
	if err != nil {
		return nil, err
	}

	if bm, err = pager.ApplyFilter(bm); err != nil {
		return nil, err
	}

	ret := &BatchMsgPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := bm.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		bm = bm.Order(pager.Order)
	} else {
		bm = bm.Order(DefaultBatchMsgOrder)
	}

	bm = bm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := bm.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type CategoryPager struct {
	Order  category.OrderOption
	Filter func(*CategoryQuery) (*CategoryQuery, error)
}

// CategoryPaginateOption enables pagination customization.
type CategoryPaginateOption func(*CategoryPager)

// DefaultCategoryOrder is the default ordering of Category.
var DefaultCategoryOrder = Desc(category.FieldID)

func newCategoryPager(opts []CategoryPaginateOption) (*CategoryPager, error) {
	pager := &CategoryPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultCategoryOrder
	}
	return pager, nil
}

func (p *CategoryPager) ApplyFilter(query *CategoryQuery) (*CategoryQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// CategoryPageList is Category PageList result.
type CategoryPageList struct {
	List        []*Category  `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (c *CategoryQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...CategoryPaginateOption,
) (*CategoryPageList, error) {

	pager, err := newCategoryPager(opts)
	if err != nil {
		return nil, err
	}

	if c, err = pager.ApplyFilter(c); err != nil {
		return nil, err
	}

	ret := &CategoryPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := c.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		c = c.Order(pager.Order)
	} else {
		c = c.Order(DefaultCategoryOrder)
	}

	c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := c.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type ChatRecordsPager struct {
	Order  chatrecords.OrderOption
	Filter func(*ChatRecordsQuery) (*ChatRecordsQuery, error)
}

// ChatRecordsPaginateOption enables pagination customization.
type ChatRecordsPaginateOption func(*ChatRecordsPager)

// DefaultChatRecordsOrder is the default ordering of ChatRecords.
var DefaultChatRecordsOrder = Desc(chatrecords.FieldID)

func newChatRecordsPager(opts []ChatRecordsPaginateOption) (*ChatRecordsPager, error) {
	pager := &ChatRecordsPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultChatRecordsOrder
	}
	return pager, nil
}

func (p *ChatRecordsPager) ApplyFilter(query *ChatRecordsQuery) (*ChatRecordsQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// ChatRecordsPageList is ChatRecords PageList result.
type ChatRecordsPageList struct {
	List        []*ChatRecords `json:"list"`
	PageDetails *PageDetails   `json:"pageDetails"`
}

func (cr *ChatRecordsQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...ChatRecordsPaginateOption,
) (*ChatRecordsPageList, error) {

	pager, err := newChatRecordsPager(opts)
	if err != nil {
		return nil, err
	}

	if cr, err = pager.ApplyFilter(cr); err != nil {
		return nil, err
	}

	ret := &ChatRecordsPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := cr.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		cr = cr.Order(pager.Order)
	} else {
		cr = cr.Order(DefaultChatRecordsOrder)
	}

	cr = cr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := cr.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type ChatSessionPager struct {
	Order  chatsession.OrderOption
	Filter func(*ChatSessionQuery) (*ChatSessionQuery, error)
}

// ChatSessionPaginateOption enables pagination customization.
type ChatSessionPaginateOption func(*ChatSessionPager)

// DefaultChatSessionOrder is the default ordering of ChatSession.
var DefaultChatSessionOrder = Desc(chatsession.FieldID)

func newChatSessionPager(opts []ChatSessionPaginateOption) (*ChatSessionPager, error) {
	pager := &ChatSessionPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultChatSessionOrder
	}
	return pager, nil
}

func (p *ChatSessionPager) ApplyFilter(query *ChatSessionQuery) (*ChatSessionQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// ChatSessionPageList is ChatSession PageList result.
type ChatSessionPageList struct {
	List        []*ChatSession `json:"list"`
	PageDetails *PageDetails   `json:"pageDetails"`
}

func (cs *ChatSessionQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...ChatSessionPaginateOption,
) (*ChatSessionPageList, error) {

	pager, err := newChatSessionPager(opts)
	if err != nil {
		return nil, err
	}

	if cs, err = pager.ApplyFilter(cs); err != nil {
		return nil, err
	}

	ret := &ChatSessionPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := cs.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		cs = cs.Order(pager.Order)
	} else {
		cs = cs.Order(DefaultChatSessionOrder)
	}

	cs = cs.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := cs.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type ContactPager struct {
	Order  contact.OrderOption
	Filter func(*ContactQuery) (*ContactQuery, error)
}

// ContactPaginateOption enables pagination customization.
type ContactPaginateOption func(*ContactPager)

// DefaultContactOrder is the default ordering of Contact.
var DefaultContactOrder = Desc(contact.FieldID)

func newContactPager(opts []ContactPaginateOption) (*ContactPager, error) {
	pager := &ContactPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultContactOrder
	}
	return pager, nil
}

func (p *ContactPager) ApplyFilter(query *ContactQuery) (*ContactQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// ContactPageList is Contact PageList result.
type ContactPageList struct {
	List        []*Contact   `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (c *ContactQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...ContactPaginateOption,
) (*ContactPageList, error) {

	pager, err := newContactPager(opts)
	if err != nil {
		return nil, err
	}

	if c, err = pager.ApplyFilter(c); err != nil {
		return nil, err
	}

	ret := &ContactPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := c.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		c = c.Order(pager.Order)
	} else {
		c = c.Order(DefaultContactOrder)
	}

	c = c.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := c.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type CreditBalancePager struct {
	Order  creditbalance.OrderOption
	Filter func(*CreditBalanceQuery) (*CreditBalanceQuery, error)
}

// CreditBalancePaginateOption enables pagination customization.
type CreditBalancePaginateOption func(*CreditBalancePager)

// DefaultCreditBalanceOrder is the default ordering of CreditBalance.
var DefaultCreditBalanceOrder = Desc(creditbalance.FieldID)

func newCreditBalancePager(opts []CreditBalancePaginateOption) (*CreditBalancePager, error) {
	pager := &CreditBalancePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultCreditBalanceOrder
	}
	return pager, nil
}

func (p *CreditBalancePager) ApplyFilter(query *CreditBalanceQuery) (*CreditBalanceQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// CreditBalancePageList is CreditBalance PageList result.
type CreditBalancePageList struct {
	List        []*CreditBalance `json:"list"`
	PageDetails *PageDetails     `json:"pageDetails"`
}

func (cb *CreditBalanceQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...CreditBalancePaginateOption,
) (*CreditBalancePageList, error) {

	pager, err := newCreditBalancePager(opts)
	if err != nil {
		return nil, err
	}

	if cb, err = pager.ApplyFilter(cb); err != nil {
		return nil, err
	}

	ret := &CreditBalancePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := cb.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		cb = cb.Order(pager.Order)
	} else {
		cb = cb.Order(DefaultCreditBalanceOrder)
	}

	cb = cb.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := cb.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type CreditUsagePager struct {
	Order  creditusage.OrderOption
	Filter func(*CreditUsageQuery) (*CreditUsageQuery, error)
}

// CreditUsagePaginateOption enables pagination customization.
type CreditUsagePaginateOption func(*CreditUsagePager)

// DefaultCreditUsageOrder is the default ordering of CreditUsage.
var DefaultCreditUsageOrder = Desc(creditusage.FieldID)

func newCreditUsagePager(opts []CreditUsagePaginateOption) (*CreditUsagePager, error) {
	pager := &CreditUsagePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultCreditUsageOrder
	}
	return pager, nil
}

func (p *CreditUsagePager) ApplyFilter(query *CreditUsageQuery) (*CreditUsageQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// CreditUsagePageList is CreditUsage PageList result.
type CreditUsagePageList struct {
	List        []*CreditUsage `json:"list"`
	PageDetails *PageDetails   `json:"pageDetails"`
}

func (cu *CreditUsageQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...CreditUsagePaginateOption,
) (*CreditUsagePageList, error) {

	pager, err := newCreditUsagePager(opts)
	if err != nil {
		return nil, err
	}

	if cu, err = pager.ApplyFilter(cu); err != nil {
		return nil, err
	}

	ret := &CreditUsagePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := cu.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		cu = cu.Order(pager.Order)
	} else {
		cu = cu.Order(DefaultCreditUsageOrder)
	}

	cu = cu.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := cu.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type EmployeePager struct {
	Order  employee.OrderOption
	Filter func(*EmployeeQuery) (*EmployeeQuery, error)
}

// EmployeePaginateOption enables pagination customization.
type EmployeePaginateOption func(*EmployeePager)

// DefaultEmployeeOrder is the default ordering of Employee.
var DefaultEmployeeOrder = Desc(employee.FieldID)

func newEmployeePager(opts []EmployeePaginateOption) (*EmployeePager, error) {
	pager := &EmployeePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultEmployeeOrder
	}
	return pager, nil
}

func (p *EmployeePager) ApplyFilter(query *EmployeeQuery) (*EmployeeQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// EmployeePageList is Employee PageList result.
type EmployeePageList struct {
	List        []*Employee  `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (e *EmployeeQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeePaginateOption,
) (*EmployeePageList, error) {

	pager, err := newEmployeePager(opts)
	if err != nil {
		return nil, err
	}

	if e, err = pager.ApplyFilter(e); err != nil {
		return nil, err
	}

	ret := &EmployeePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := e.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		e = e.Order(pager.Order)
	} else {
		e = e.Order(DefaultEmployeeOrder)
	}

	e = e.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := e.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type EmployeeConfigPager struct {
	Order  employeeconfig.OrderOption
	Filter func(*EmployeeConfigQuery) (*EmployeeConfigQuery, error)
}

// EmployeeConfigPaginateOption enables pagination customization.
type EmployeeConfigPaginateOption func(*EmployeeConfigPager)

// DefaultEmployeeConfigOrder is the default ordering of EmployeeConfig.
var DefaultEmployeeConfigOrder = Desc(employeeconfig.FieldID)

func newEmployeeConfigPager(opts []EmployeeConfigPaginateOption) (*EmployeeConfigPager, error) {
	pager := &EmployeeConfigPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultEmployeeConfigOrder
	}
	return pager, nil
}

func (p *EmployeeConfigPager) ApplyFilter(query *EmployeeConfigQuery) (*EmployeeConfigQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// EmployeeConfigPageList is EmployeeConfig PageList result.
type EmployeeConfigPageList struct {
	List        []*EmployeeConfig `json:"list"`
	PageDetails *PageDetails      `json:"pageDetails"`
}

func (ec *EmployeeConfigQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...EmployeeConfigPaginateOption,
) (*EmployeeConfigPageList, error) {

	pager, err := newEmployeeConfigPager(opts)
	if err != nil {
		return nil, err
	}

	if ec, err = pager.ApplyFilter(ec); err != nil {
		return nil, err
	}

	ret := &EmployeeConfigPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ec.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ec = ec.Order(pager.Order)
	} else {
		ec = ec.Order(DefaultEmployeeConfigOrder)
	}

	ec = ec.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ec.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type LabelPager struct {
	Order  label.OrderOption
	Filter func(*LabelQuery) (*LabelQuery, error)
}

// LabelPaginateOption enables pagination customization.
type LabelPaginateOption func(*LabelPager)

// DefaultLabelOrder is the default ordering of Label.
var DefaultLabelOrder = Desc(label.FieldID)

func newLabelPager(opts []LabelPaginateOption) (*LabelPager, error) {
	pager := &LabelPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultLabelOrder
	}
	return pager, nil
}

func (p *LabelPager) ApplyFilter(query *LabelQuery) (*LabelQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// LabelPageList is Label PageList result.
type LabelPageList struct {
	List        []*Label     `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (l *LabelQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelPaginateOption,
) (*LabelPageList, error) {

	pager, err := newLabelPager(opts)
	if err != nil {
		return nil, err
	}

	if l, err = pager.ApplyFilter(l); err != nil {
		return nil, err
	}

	ret := &LabelPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := l.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		l = l.Order(pager.Order)
	} else {
		l = l.Order(DefaultLabelOrder)
	}

	l = l.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := l.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type LabelRelationshipPager struct {
	Order  labelrelationship.OrderOption
	Filter func(*LabelRelationshipQuery) (*LabelRelationshipQuery, error)
}

// LabelRelationshipPaginateOption enables pagination customization.
type LabelRelationshipPaginateOption func(*LabelRelationshipPager)

// DefaultLabelRelationshipOrder is the default ordering of LabelRelationship.
var DefaultLabelRelationshipOrder = Desc(labelrelationship.FieldID)

func newLabelRelationshipPager(opts []LabelRelationshipPaginateOption) (*LabelRelationshipPager, error) {
	pager := &LabelRelationshipPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultLabelRelationshipOrder
	}
	return pager, nil
}

func (p *LabelRelationshipPager) ApplyFilter(query *LabelRelationshipQuery) (*LabelRelationshipQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// LabelRelationshipPageList is LabelRelationship PageList result.
type LabelRelationshipPageList struct {
	List        []*LabelRelationship `json:"list"`
	PageDetails *PageDetails         `json:"pageDetails"`
}

func (lr *LabelRelationshipQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelRelationshipPaginateOption,
) (*LabelRelationshipPageList, error) {

	pager, err := newLabelRelationshipPager(opts)
	if err != nil {
		return nil, err
	}

	if lr, err = pager.ApplyFilter(lr); err != nil {
		return nil, err
	}

	ret := &LabelRelationshipPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := lr.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		lr = lr.Order(pager.Order)
	} else {
		lr = lr.Order(DefaultLabelRelationshipOrder)
	}

	lr = lr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := lr.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type LabelTaggingPager struct {
	Order  labeltagging.OrderOption
	Filter func(*LabelTaggingQuery) (*LabelTaggingQuery, error)
}

// LabelTaggingPaginateOption enables pagination customization.
type LabelTaggingPaginateOption func(*LabelTaggingPager)

// DefaultLabelTaggingOrder is the default ordering of LabelTagging.
var DefaultLabelTaggingOrder = Desc(labeltagging.FieldID)

func newLabelTaggingPager(opts []LabelTaggingPaginateOption) (*LabelTaggingPager, error) {
	pager := &LabelTaggingPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultLabelTaggingOrder
	}
	return pager, nil
}

func (p *LabelTaggingPager) ApplyFilter(query *LabelTaggingQuery) (*LabelTaggingQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// LabelTaggingPageList is LabelTagging PageList result.
type LabelTaggingPageList struct {
	List        []*LabelTagging `json:"list"`
	PageDetails *PageDetails    `json:"pageDetails"`
}

func (lt *LabelTaggingQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...LabelTaggingPaginateOption,
) (*LabelTaggingPageList, error) {

	pager, err := newLabelTaggingPager(opts)
	if err != nil {
		return nil, err
	}

	if lt, err = pager.ApplyFilter(lt); err != nil {
		return nil, err
	}

	ret := &LabelTaggingPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := lt.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		lt = lt.Order(pager.Order)
	} else {
		lt = lt.Order(DefaultLabelTaggingOrder)
	}

	lt = lt.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := lt.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type MessagePager struct {
	Order  message.OrderOption
	Filter func(*MessageQuery) (*MessageQuery, error)
}

// MessagePaginateOption enables pagination customization.
type MessagePaginateOption func(*MessagePager)

// DefaultMessageOrder is the default ordering of Message.
var DefaultMessageOrder = Desc(message.FieldID)

func newMessagePager(opts []MessagePaginateOption) (*MessagePager, error) {
	pager := &MessagePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultMessageOrder
	}
	return pager, nil
}

func (p *MessagePager) ApplyFilter(query *MessageQuery) (*MessageQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// MessagePageList is Message PageList result.
type MessagePageList struct {
	List        []*Message   `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (m *MessageQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessagePaginateOption,
) (*MessagePageList, error) {

	pager, err := newMessagePager(opts)
	if err != nil {
		return nil, err
	}

	if m, err = pager.ApplyFilter(m); err != nil {
		return nil, err
	}

	ret := &MessagePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := m.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		m = m.Order(pager.Order)
	} else {
		m = m.Order(DefaultMessageOrder)
	}

	m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := m.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type MessageRecordsPager struct {
	Order  messagerecords.OrderOption
	Filter func(*MessageRecordsQuery) (*MessageRecordsQuery, error)
}

// MessageRecordsPaginateOption enables pagination customization.
type MessageRecordsPaginateOption func(*MessageRecordsPager)

// DefaultMessageRecordsOrder is the default ordering of MessageRecords.
var DefaultMessageRecordsOrder = Desc(messagerecords.FieldID)

func newMessageRecordsPager(opts []MessageRecordsPaginateOption) (*MessageRecordsPager, error) {
	pager := &MessageRecordsPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultMessageRecordsOrder
	}
	return pager, nil
}

func (p *MessageRecordsPager) ApplyFilter(query *MessageRecordsQuery) (*MessageRecordsQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// MessageRecordsPageList is MessageRecords PageList result.
type MessageRecordsPageList struct {
	List        []*MessageRecords `json:"list"`
	PageDetails *PageDetails      `json:"pageDetails"`
}

func (mr *MessageRecordsQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...MessageRecordsPaginateOption,
) (*MessageRecordsPageList, error) {

	pager, err := newMessageRecordsPager(opts)
	if err != nil {
		return nil, err
	}

	if mr, err = pager.ApplyFilter(mr); err != nil {
		return nil, err
	}

	ret := &MessageRecordsPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := mr.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		mr = mr.Order(pager.Order)
	} else {
		mr = mr.Order(DefaultMessageRecordsOrder)
	}

	mr = mr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := mr.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type MsgPager struct {
	Order  msg.OrderOption
	Filter func(*MsgQuery) (*MsgQuery, error)
}

// MsgPaginateOption enables pagination customization.
type MsgPaginateOption func(*MsgPager)

// DefaultMsgOrder is the default ordering of Msg.
var DefaultMsgOrder = Desc(msg.FieldID)

func newMsgPager(opts []MsgPaginateOption) (*MsgPager, error) {
	pager := &MsgPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultMsgOrder
	}
	return pager, nil
}

func (p *MsgPager) ApplyFilter(query *MsgQuery) (*MsgQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// MsgPageList is Msg PageList result.
type MsgPageList struct {
	List        []*Msg       `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (m *MsgQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...MsgPaginateOption,
) (*MsgPageList, error) {

	pager, err := newMsgPager(opts)
	if err != nil {
		return nil, err
	}

	if m, err = pager.ApplyFilter(m); err != nil {
		return nil, err
	}

	ret := &MsgPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := m.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		m = m.Order(pager.Order)
	} else {
		m = m.Order(DefaultMsgOrder)
	}

	m = m.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := m.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type PayRechargePager struct {
	Order  payrecharge.OrderOption
	Filter func(*PayRechargeQuery) (*PayRechargeQuery, error)
}

// PayRechargePaginateOption enables pagination customization.
type PayRechargePaginateOption func(*PayRechargePager)

// DefaultPayRechargeOrder is the default ordering of PayRecharge.
var DefaultPayRechargeOrder = Desc(payrecharge.FieldID)

func newPayRechargePager(opts []PayRechargePaginateOption) (*PayRechargePager, error) {
	pager := &PayRechargePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultPayRechargeOrder
	}
	return pager, nil
}

func (p *PayRechargePager) ApplyFilter(query *PayRechargeQuery) (*PayRechargeQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// PayRechargePageList is PayRecharge PageList result.
type PayRechargePageList struct {
	List        []*PayRecharge `json:"list"`
	PageDetails *PageDetails   `json:"pageDetails"`
}

func (pr *PayRechargeQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...PayRechargePaginateOption,
) (*PayRechargePageList, error) {

	pager, err := newPayRechargePager(opts)
	if err != nil {
		return nil, err
	}

	if pr, err = pager.ApplyFilter(pr); err != nil {
		return nil, err
	}

	ret := &PayRechargePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := pr.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		pr = pr.Order(pager.Order)
	} else {
		pr = pr.Order(DefaultPayRechargeOrder)
	}

	pr = pr.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := pr.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type ServerPager struct {
	Order  server.OrderOption
	Filter func(*ServerQuery) (*ServerQuery, error)
}

// ServerPaginateOption enables pagination customization.
type ServerPaginateOption func(*ServerPager)

// DefaultServerOrder is the default ordering of Server.
var DefaultServerOrder = Desc(server.FieldID)

func newServerPager(opts []ServerPaginateOption) (*ServerPager, error) {
	pager := &ServerPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultServerOrder
	}
	return pager, nil
}

func (p *ServerPager) ApplyFilter(query *ServerQuery) (*ServerQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// ServerPageList is Server PageList result.
type ServerPageList struct {
	List        []*Server    `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (s *ServerQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...ServerPaginateOption,
) (*ServerPageList, error) {

	pager, err := newServerPager(opts)
	if err != nil {
		return nil, err
	}

	if s, err = pager.ApplyFilter(s); err != nil {
		return nil, err
	}

	ret := &ServerPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := s.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		s = s.Order(pager.Order)
	} else {
		s = s.Order(DefaultServerOrder)
	}

	s = s.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := s.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type SopNodePager struct {
	Order  sopnode.OrderOption
	Filter func(*SopNodeQuery) (*SopNodeQuery, error)
}

// SopNodePaginateOption enables pagination customization.
type SopNodePaginateOption func(*SopNodePager)

// DefaultSopNodeOrder is the default ordering of SopNode.
var DefaultSopNodeOrder = Desc(sopnode.FieldID)

func newSopNodePager(opts []SopNodePaginateOption) (*SopNodePager, error) {
	pager := &SopNodePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultSopNodeOrder
	}
	return pager, nil
}

func (p *SopNodePager) ApplyFilter(query *SopNodeQuery) (*SopNodeQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// SopNodePageList is SopNode PageList result.
type SopNodePageList struct {
	List        []*SopNode   `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (sn *SopNodeQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopNodePaginateOption,
) (*SopNodePageList, error) {

	pager, err := newSopNodePager(opts)
	if err != nil {
		return nil, err
	}

	if sn, err = pager.ApplyFilter(sn); err != nil {
		return nil, err
	}

	ret := &SopNodePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := sn.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		sn = sn.Order(pager.Order)
	} else {
		sn = sn.Order(DefaultSopNodeOrder)
	}

	sn = sn.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := sn.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type SopStagePager struct {
	Order  sopstage.OrderOption
	Filter func(*SopStageQuery) (*SopStageQuery, error)
}

// SopStagePaginateOption enables pagination customization.
type SopStagePaginateOption func(*SopStagePager)

// DefaultSopStageOrder is the default ordering of SopStage.
var DefaultSopStageOrder = Desc(sopstage.FieldID)

func newSopStagePager(opts []SopStagePaginateOption) (*SopStagePager, error) {
	pager := &SopStagePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultSopStageOrder
	}
	return pager, nil
}

func (p *SopStagePager) ApplyFilter(query *SopStageQuery) (*SopStageQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// SopStagePageList is SopStage PageList result.
type SopStagePageList struct {
	List        []*SopStage  `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (ss *SopStageQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopStagePaginateOption,
) (*SopStagePageList, error) {

	pager, err := newSopStagePager(opts)
	if err != nil {
		return nil, err
	}

	if ss, err = pager.ApplyFilter(ss); err != nil {
		return nil, err
	}

	ret := &SopStagePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ss.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ss = ss.Order(pager.Order)
	} else {
		ss = ss.Order(DefaultSopStageOrder)
	}

	ss = ss.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ss.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type SopTaskPager struct {
	Order  soptask.OrderOption
	Filter func(*SopTaskQuery) (*SopTaskQuery, error)
}

// SopTaskPaginateOption enables pagination customization.
type SopTaskPaginateOption func(*SopTaskPager)

// DefaultSopTaskOrder is the default ordering of SopTask.
var DefaultSopTaskOrder = Desc(soptask.FieldID)

func newSopTaskPager(opts []SopTaskPaginateOption) (*SopTaskPager, error) {
	pager := &SopTaskPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultSopTaskOrder
	}
	return pager, nil
}

func (p *SopTaskPager) ApplyFilter(query *SopTaskQuery) (*SopTaskQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// SopTaskPageList is SopTask PageList result.
type SopTaskPageList struct {
	List        []*SopTask   `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (st *SopTaskQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...SopTaskPaginateOption,
) (*SopTaskPageList, error) {

	pager, err := newSopTaskPager(opts)
	if err != nil {
		return nil, err
	}

	if st, err = pager.ApplyFilter(st); err != nil {
		return nil, err
	}

	ret := &SopTaskPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := st.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		st = st.Order(pager.Order)
	} else {
		st = st.Order(DefaultSopTaskOrder)
	}

	st = st.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := st.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type TokenPager struct {
	Order  token.OrderOption
	Filter func(*TokenQuery) (*TokenQuery, error)
}

// TokenPaginateOption enables pagination customization.
type TokenPaginateOption func(*TokenPager)

// DefaultTokenOrder is the default ordering of Token.
var DefaultTokenOrder = Desc(token.FieldID)

func newTokenPager(opts []TokenPaginateOption) (*TokenPager, error) {
	pager := &TokenPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultTokenOrder
	}
	return pager, nil
}

func (p *TokenPager) ApplyFilter(query *TokenQuery) (*TokenQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// TokenPageList is Token PageList result.
type TokenPageList struct {
	List        []*Token     `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (t *TokenQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...TokenPaginateOption,
) (*TokenPageList, error) {

	pager, err := newTokenPager(opts)
	if err != nil {
		return nil, err
	}

	if t, err = pager.ApplyFilter(t); err != nil {
		return nil, err
	}

	ret := &TokenPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := t.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		t = t.Order(pager.Order)
	} else {
		t = t.Order(DefaultTokenOrder)
	}

	t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := t.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type TutorialPager struct {
	Order  tutorial.OrderOption
	Filter func(*TutorialQuery) (*TutorialQuery, error)
}

// TutorialPaginateOption enables pagination customization.
type TutorialPaginateOption func(*TutorialPager)

// DefaultTutorialOrder is the default ordering of Tutorial.
var DefaultTutorialOrder = Desc(tutorial.FieldID)

func newTutorialPager(opts []TutorialPaginateOption) (*TutorialPager, error) {
	pager := &TutorialPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultTutorialOrder
	}
	return pager, nil
}

func (p *TutorialPager) ApplyFilter(query *TutorialQuery) (*TutorialQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// TutorialPageList is Tutorial PageList result.
type TutorialPageList struct {
	List        []*Tutorial  `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (t *TutorialQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...TutorialPaginateOption,
) (*TutorialPageList, error) {

	pager, err := newTutorialPager(opts)
	if err != nil {
		return nil, err
	}

	if t, err = pager.ApplyFilter(t); err != nil {
		return nil, err
	}

	ret := &TutorialPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := t.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		t = t.Order(pager.Order)
	} else {
		t = t.Order(DefaultTutorialOrder)
	}

	t = t.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := t.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type UsageDetailPager struct {
	Order  usagedetail.OrderOption
	Filter func(*UsageDetailQuery) (*UsageDetailQuery, error)
}

// UsageDetailPaginateOption enables pagination customization.
type UsageDetailPaginateOption func(*UsageDetailPager)

// DefaultUsageDetailOrder is the default ordering of UsageDetail.
var DefaultUsageDetailOrder = Desc(usagedetail.FieldID)

func newUsageDetailPager(opts []UsageDetailPaginateOption) (*UsageDetailPager, error) {
	pager := &UsageDetailPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultUsageDetailOrder
	}
	return pager, nil
}

func (p *UsageDetailPager) ApplyFilter(query *UsageDetailQuery) (*UsageDetailQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// UsageDetailPageList is UsageDetail PageList result.
type UsageDetailPageList struct {
	List        []*UsageDetail `json:"list"`
	PageDetails *PageDetails   `json:"pageDetails"`
}

func (ud *UsageDetailQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageDetailPaginateOption,
) (*UsageDetailPageList, error) {

	pager, err := newUsageDetailPager(opts)
	if err != nil {
		return nil, err
	}

	if ud, err = pager.ApplyFilter(ud); err != nil {
		return nil, err
	}

	ret := &UsageDetailPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ud.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ud = ud.Order(pager.Order)
	} else {
		ud = ud.Order(DefaultUsageDetailOrder)
	}

	ud = ud.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ud.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type UsageStatisticDayPager struct {
	Order  usagestatisticday.OrderOption
	Filter func(*UsageStatisticDayQuery) (*UsageStatisticDayQuery, error)
}

// UsageStatisticDayPaginateOption enables pagination customization.
type UsageStatisticDayPaginateOption func(*UsageStatisticDayPager)

// DefaultUsageStatisticDayOrder is the default ordering of UsageStatisticDay.
var DefaultUsageStatisticDayOrder = Desc(usagestatisticday.FieldID)

func newUsageStatisticDayPager(opts []UsageStatisticDayPaginateOption) (*UsageStatisticDayPager, error) {
	pager := &UsageStatisticDayPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultUsageStatisticDayOrder
	}
	return pager, nil
}

func (p *UsageStatisticDayPager) ApplyFilter(query *UsageStatisticDayQuery) (*UsageStatisticDayQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// UsageStatisticDayPageList is UsageStatisticDay PageList result.
type UsageStatisticDayPageList struct {
	List        []*UsageStatisticDay `json:"list"`
	PageDetails *PageDetails         `json:"pageDetails"`
}

func (usd *UsageStatisticDayQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageStatisticDayPaginateOption,
) (*UsageStatisticDayPageList, error) {

	pager, err := newUsageStatisticDayPager(opts)
	if err != nil {
		return nil, err
	}

	if usd, err = pager.ApplyFilter(usd); err != nil {
		return nil, err
	}

	ret := &UsageStatisticDayPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := usd.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		usd = usd.Order(pager.Order)
	} else {
		usd = usd.Order(DefaultUsageStatisticDayOrder)
	}

	usd = usd.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := usd.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type UsageStatisticHourPager struct {
	Order  usagestatistichour.OrderOption
	Filter func(*UsageStatisticHourQuery) (*UsageStatisticHourQuery, error)
}

// UsageStatisticHourPaginateOption enables pagination customization.
type UsageStatisticHourPaginateOption func(*UsageStatisticHourPager)

// DefaultUsageStatisticHourOrder is the default ordering of UsageStatisticHour.
var DefaultUsageStatisticHourOrder = Desc(usagestatistichour.FieldID)

func newUsageStatisticHourPager(opts []UsageStatisticHourPaginateOption) (*UsageStatisticHourPager, error) {
	pager := &UsageStatisticHourPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultUsageStatisticHourOrder
	}
	return pager, nil
}

func (p *UsageStatisticHourPager) ApplyFilter(query *UsageStatisticHourQuery) (*UsageStatisticHourQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// UsageStatisticHourPageList is UsageStatisticHour PageList result.
type UsageStatisticHourPageList struct {
	List        []*UsageStatisticHour `json:"list"`
	PageDetails *PageDetails          `json:"pageDetails"`
}

func (ush *UsageStatisticHourQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageStatisticHourPaginateOption,
) (*UsageStatisticHourPageList, error) {

	pager, err := newUsageStatisticHourPager(opts)
	if err != nil {
		return nil, err
	}

	if ush, err = pager.ApplyFilter(ush); err != nil {
		return nil, err
	}

	ret := &UsageStatisticHourPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ush.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ush = ush.Order(pager.Order)
	} else {
		ush = ush.Order(DefaultUsageStatisticHourOrder)
	}

	ush = ush.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ush.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type UsageStatisticMonthPager struct {
	Order  usagestatisticmonth.OrderOption
	Filter func(*UsageStatisticMonthQuery) (*UsageStatisticMonthQuery, error)
}

// UsageStatisticMonthPaginateOption enables pagination customization.
type UsageStatisticMonthPaginateOption func(*UsageStatisticMonthPager)

// DefaultUsageStatisticMonthOrder is the default ordering of UsageStatisticMonth.
var DefaultUsageStatisticMonthOrder = Desc(usagestatisticmonth.FieldID)

func newUsageStatisticMonthPager(opts []UsageStatisticMonthPaginateOption) (*UsageStatisticMonthPager, error) {
	pager := &UsageStatisticMonthPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultUsageStatisticMonthOrder
	}
	return pager, nil
}

func (p *UsageStatisticMonthPager) ApplyFilter(query *UsageStatisticMonthQuery) (*UsageStatisticMonthQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// UsageStatisticMonthPageList is UsageStatisticMonth PageList result.
type UsageStatisticMonthPageList struct {
	List        []*UsageStatisticMonth `json:"list"`
	PageDetails *PageDetails           `json:"pageDetails"`
}

func (usm *UsageStatisticMonthQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageStatisticMonthPaginateOption,
) (*UsageStatisticMonthPageList, error) {

	pager, err := newUsageStatisticMonthPager(opts)
	if err != nil {
		return nil, err
	}

	if usm, err = pager.ApplyFilter(usm); err != nil {
		return nil, err
	}

	ret := &UsageStatisticMonthPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := usm.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		usm = usm.Order(pager.Order)
	} else {
		usm = usm.Order(DefaultUsageStatisticMonthOrder)
	}

	usm = usm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := usm.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type UsageTotalPager struct {
	Order  usagetotal.OrderOption
	Filter func(*UsageTotalQuery) (*UsageTotalQuery, error)
}

// UsageTotalPaginateOption enables pagination customization.
type UsageTotalPaginateOption func(*UsageTotalPager)

// DefaultUsageTotalOrder is the default ordering of UsageTotal.
var DefaultUsageTotalOrder = Desc(usagetotal.FieldID)

func newUsageTotalPager(opts []UsageTotalPaginateOption) (*UsageTotalPager, error) {
	pager := &UsageTotalPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultUsageTotalOrder
	}
	return pager, nil
}

func (p *UsageTotalPager) ApplyFilter(query *UsageTotalQuery) (*UsageTotalQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// UsageTotalPageList is UsageTotal PageList result.
type UsageTotalPageList struct {
	List        []*UsageTotal `json:"list"`
	PageDetails *PageDetails  `json:"pageDetails"`
}

func (ut *UsageTotalQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...UsageTotalPaginateOption,
) (*UsageTotalPageList, error) {

	pager, err := newUsageTotalPager(opts)
	if err != nil {
		return nil, err
	}

	if ut, err = pager.ApplyFilter(ut); err != nil {
		return nil, err
	}

	ret := &UsageTotalPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := ut.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		ut = ut.Order(pager.Order)
	} else {
		ut = ut.Order(DefaultUsageTotalOrder)
	}

	ut = ut.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := ut.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WhatsappPager struct {
	Order  whatsapp.OrderOption
	Filter func(*WhatsappQuery) (*WhatsappQuery, error)
}

// WhatsappPaginateOption enables pagination customization.
type WhatsappPaginateOption func(*WhatsappPager)

// DefaultWhatsappOrder is the default ordering of Whatsapp.
var DefaultWhatsappOrder = Desc(whatsapp.FieldID)

func newWhatsappPager(opts []WhatsappPaginateOption) (*WhatsappPager, error) {
	pager := &WhatsappPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWhatsappOrder
	}
	return pager, nil
}

func (p *WhatsappPager) ApplyFilter(query *WhatsappQuery) (*WhatsappQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WhatsappPageList is Whatsapp PageList result.
type WhatsappPageList struct {
	List        []*Whatsapp  `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (w *WhatsappQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WhatsappPaginateOption,
) (*WhatsappPageList, error) {

	pager, err := newWhatsappPager(opts)
	if err != nil {
		return nil, err
	}

	if w, err = pager.ApplyFilter(w); err != nil {
		return nil, err
	}

	ret := &WhatsappPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := w.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		w = w.Order(pager.Order)
	} else {
		w = w.Order(DefaultWhatsappOrder)
	}

	w = w.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := w.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WhatsappChannelPager struct {
	Order  whatsappchannel.OrderOption
	Filter func(*WhatsappChannelQuery) (*WhatsappChannelQuery, error)
}

// WhatsappChannelPaginateOption enables pagination customization.
type WhatsappChannelPaginateOption func(*WhatsappChannelPager)

// DefaultWhatsappChannelOrder is the default ordering of WhatsappChannel.
var DefaultWhatsappChannelOrder = Desc(whatsappchannel.FieldID)

func newWhatsappChannelPager(opts []WhatsappChannelPaginateOption) (*WhatsappChannelPager, error) {
	pager := &WhatsappChannelPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWhatsappChannelOrder
	}
	return pager, nil
}

func (p *WhatsappChannelPager) ApplyFilter(query *WhatsappChannelQuery) (*WhatsappChannelQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WhatsappChannelPageList is WhatsappChannel PageList result.
type WhatsappChannelPageList struct {
	List        []*WhatsappChannel `json:"list"`
	PageDetails *PageDetails       `json:"pageDetails"`
}

func (wc *WhatsappChannelQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WhatsappChannelPaginateOption,
) (*WhatsappChannelPageList, error) {

	pager, err := newWhatsappChannelPager(opts)
	if err != nil {
		return nil, err
	}

	if wc, err = pager.ApplyFilter(wc); err != nil {
		return nil, err
	}

	ret := &WhatsappChannelPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := wc.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		wc = wc.Order(pager.Order)
	} else {
		wc = wc.Order(DefaultWhatsappChannelOrder)
	}

	wc = wc.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := wc.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WorkExperiencePager struct {
	Order  workexperience.OrderOption
	Filter func(*WorkExperienceQuery) (*WorkExperienceQuery, error)
}

// WorkExperiencePaginateOption enables pagination customization.
type WorkExperiencePaginateOption func(*WorkExperiencePager)

// DefaultWorkExperienceOrder is the default ordering of WorkExperience.
var DefaultWorkExperienceOrder = Desc(workexperience.FieldID)

func newWorkExperiencePager(opts []WorkExperiencePaginateOption) (*WorkExperiencePager, error) {
	pager := &WorkExperiencePager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWorkExperienceOrder
	}
	return pager, nil
}

func (p *WorkExperiencePager) ApplyFilter(query *WorkExperienceQuery) (*WorkExperienceQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WorkExperiencePageList is WorkExperience PageList result.
type WorkExperiencePageList struct {
	List        []*WorkExperience `json:"list"`
	PageDetails *PageDetails      `json:"pageDetails"`
}

func (we *WorkExperienceQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WorkExperiencePaginateOption,
) (*WorkExperiencePageList, error) {

	pager, err := newWorkExperiencePager(opts)
	if err != nil {
		return nil, err
	}

	if we, err = pager.ApplyFilter(we); err != nil {
		return nil, err
	}

	ret := &WorkExperiencePageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := we.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		we = we.Order(pager.Order)
	} else {
		we = we.Order(DefaultWorkExperienceOrder)
	}

	we = we.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := we.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WpChatroomPager struct {
	Order  wpchatroom.OrderOption
	Filter func(*WpChatroomQuery) (*WpChatroomQuery, error)
}

// WpChatroomPaginateOption enables pagination customization.
type WpChatroomPaginateOption func(*WpChatroomPager)

// DefaultWpChatroomOrder is the default ordering of WpChatroom.
var DefaultWpChatroomOrder = Desc(wpchatroom.FieldID)

func newWpChatroomPager(opts []WpChatroomPaginateOption) (*WpChatroomPager, error) {
	pager := &WpChatroomPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWpChatroomOrder
	}
	return pager, nil
}

func (p *WpChatroomPager) ApplyFilter(query *WpChatroomQuery) (*WpChatroomQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WpChatroomPageList is WpChatroom PageList result.
type WpChatroomPageList struct {
	List        []*WpChatroom `json:"list"`
	PageDetails *PageDetails  `json:"pageDetails"`
}

func (wc *WpChatroomQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WpChatroomPaginateOption,
) (*WpChatroomPageList, error) {

	pager, err := newWpChatroomPager(opts)
	if err != nil {
		return nil, err
	}

	if wc, err = pager.ApplyFilter(wc); err != nil {
		return nil, err
	}

	ret := &WpChatroomPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := wc.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		wc = wc.Order(pager.Order)
	} else {
		wc = wc.Order(DefaultWpChatroomOrder)
	}

	wc = wc.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := wc.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WpChatroomMemberPager struct {
	Order  wpchatroommember.OrderOption
	Filter func(*WpChatroomMemberQuery) (*WpChatroomMemberQuery, error)
}

// WpChatroomMemberPaginateOption enables pagination customization.
type WpChatroomMemberPaginateOption func(*WpChatroomMemberPager)

// DefaultWpChatroomMemberOrder is the default ordering of WpChatroomMember.
var DefaultWpChatroomMemberOrder = Desc(wpchatroommember.FieldID)

func newWpChatroomMemberPager(opts []WpChatroomMemberPaginateOption) (*WpChatroomMemberPager, error) {
	pager := &WpChatroomMemberPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWpChatroomMemberOrder
	}
	return pager, nil
}

func (p *WpChatroomMemberPager) ApplyFilter(query *WpChatroomMemberQuery) (*WpChatroomMemberQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WpChatroomMemberPageList is WpChatroomMember PageList result.
type WpChatroomMemberPageList struct {
	List        []*WpChatroomMember `json:"list"`
	PageDetails *PageDetails        `json:"pageDetails"`
}

func (wcm *WpChatroomMemberQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WpChatroomMemberPaginateOption,
) (*WpChatroomMemberPageList, error) {

	pager, err := newWpChatroomMemberPager(opts)
	if err != nil {
		return nil, err
	}

	if wcm, err = pager.ApplyFilter(wcm); err != nil {
		return nil, err
	}

	ret := &WpChatroomMemberPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := wcm.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		wcm = wcm.Order(pager.Order)
	} else {
		wcm = wcm.Order(DefaultWpChatroomMemberOrder)
	}

	wcm = wcm.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := wcm.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WxPager struct {
	Order  wx.OrderOption
	Filter func(*WxQuery) (*WxQuery, error)
}

// WxPaginateOption enables pagination customization.
type WxPaginateOption func(*WxPager)

// DefaultWxOrder is the default ordering of Wx.
var DefaultWxOrder = Desc(wx.FieldID)

func newWxPager(opts []WxPaginateOption) (*WxPager, error) {
	pager := &WxPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWxOrder
	}
	return pager, nil
}

func (p *WxPager) ApplyFilter(query *WxQuery) (*WxQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WxPageList is Wx PageList result.
type WxPageList struct {
	List        []*Wx        `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (w *WxQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxPaginateOption,
) (*WxPageList, error) {

	pager, err := newWxPager(opts)
	if err != nil {
		return nil, err
	}

	if w, err = pager.ApplyFilter(w); err != nil {
		return nil, err
	}

	ret := &WxPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := w.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		w = w.Order(pager.Order)
	} else {
		w = w.Order(DefaultWxOrder)
	}

	w = w.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := w.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WxCardPager struct {
	Order  wxcard.OrderOption
	Filter func(*WxCardQuery) (*WxCardQuery, error)
}

// WxCardPaginateOption enables pagination customization.
type WxCardPaginateOption func(*WxCardPager)

// DefaultWxCardOrder is the default ordering of WxCard.
var DefaultWxCardOrder = Desc(wxcard.FieldID)

func newWxCardPager(opts []WxCardPaginateOption) (*WxCardPager, error) {
	pager := &WxCardPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWxCardOrder
	}
	return pager, nil
}

func (p *WxCardPager) ApplyFilter(query *WxCardQuery) (*WxCardQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WxCardPageList is WxCard PageList result.
type WxCardPageList struct {
	List        []*WxCard    `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (wc *WxCardQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardPaginateOption,
) (*WxCardPageList, error) {

	pager, err := newWxCardPager(opts)
	if err != nil {
		return nil, err
	}

	if wc, err = pager.ApplyFilter(wc); err != nil {
		return nil, err
	}

	ret := &WxCardPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := wc.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		wc = wc.Order(pager.Order)
	} else {
		wc = wc.Order(DefaultWxCardOrder)
	}

	wc = wc.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := wc.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WxCardUserPager struct {
	Order  wxcarduser.OrderOption
	Filter func(*WxCardUserQuery) (*WxCardUserQuery, error)
}

// WxCardUserPaginateOption enables pagination customization.
type WxCardUserPaginateOption func(*WxCardUserPager)

// DefaultWxCardUserOrder is the default ordering of WxCardUser.
var DefaultWxCardUserOrder = Desc(wxcarduser.FieldID)

func newWxCardUserPager(opts []WxCardUserPaginateOption) (*WxCardUserPager, error) {
	pager := &WxCardUserPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWxCardUserOrder
	}
	return pager, nil
}

func (p *WxCardUserPager) ApplyFilter(query *WxCardUserQuery) (*WxCardUserQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WxCardUserPageList is WxCardUser PageList result.
type WxCardUserPageList struct {
	List        []*WxCardUser `json:"list"`
	PageDetails *PageDetails  `json:"pageDetails"`
}

func (wcu *WxCardUserQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardUserPaginateOption,
) (*WxCardUserPageList, error) {

	pager, err := newWxCardUserPager(opts)
	if err != nil {
		return nil, err
	}

	if wcu, err = pager.ApplyFilter(wcu); err != nil {
		return nil, err
	}

	ret := &WxCardUserPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := wcu.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		wcu = wcu.Order(pager.Order)
	} else {
		wcu = wcu.Order(DefaultWxCardUserOrder)
	}

	wcu = wcu.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := wcu.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type WxCardVisitPager struct {
	Order  wxcardvisit.OrderOption
	Filter func(*WxCardVisitQuery) (*WxCardVisitQuery, error)
}

// WxCardVisitPaginateOption enables pagination customization.
type WxCardVisitPaginateOption func(*WxCardVisitPager)

// DefaultWxCardVisitOrder is the default ordering of WxCardVisit.
var DefaultWxCardVisitOrder = Desc(wxcardvisit.FieldID)

func newWxCardVisitPager(opts []WxCardVisitPaginateOption) (*WxCardVisitPager, error) {
	pager := &WxCardVisitPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultWxCardVisitOrder
	}
	return pager, nil
}

func (p *WxCardVisitPager) ApplyFilter(query *WxCardVisitQuery) (*WxCardVisitQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// WxCardVisitPageList is WxCardVisit PageList result.
type WxCardVisitPageList struct {
	List        []*WxCardVisit `json:"list"`
	PageDetails *PageDetails   `json:"pageDetails"`
}

func (wcv *WxCardVisitQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...WxCardVisitPaginateOption,
) (*WxCardVisitPageList, error) {

	pager, err := newWxCardVisitPager(opts)
	if err != nil {
		return nil, err
	}

	if wcv, err = pager.ApplyFilter(wcv); err != nil {
		return nil, err
	}

	ret := &WxCardVisitPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := wcv.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		wcv = wcv.Order(pager.Order)
	} else {
		wcv = wcv.Order(DefaultWxCardVisitOrder)
	}

	wcv = wcv.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := wcv.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}

type XunjiPager struct {
	Order  xunji.OrderOption
	Filter func(*XunjiQuery) (*XunjiQuery, error)
}

// XunjiPaginateOption enables pagination customization.
type XunjiPaginateOption func(*XunjiPager)

// DefaultXunjiOrder is the default ordering of Xunji.
var DefaultXunjiOrder = Desc(xunji.FieldID)

func newXunjiPager(opts []XunjiPaginateOption) (*XunjiPager, error) {
	pager := &XunjiPager{}
	for _, opt := range opts {
		opt(pager)
	}
	if pager.Order == nil {
		pager.Order = DefaultXunjiOrder
	}
	return pager, nil
}

func (p *XunjiPager) ApplyFilter(query *XunjiQuery) (*XunjiQuery, error) {
	if p.Filter != nil {
		return p.Filter(query)
	}
	return query, nil
}

// XunjiPageList is Xunji PageList result.
type XunjiPageList struct {
	List        []*Xunji     `json:"list"`
	PageDetails *PageDetails `json:"pageDetails"`
}

func (x *XunjiQuery) Page(
	ctx context.Context, pageNum uint64, pageSize uint64, opts ...XunjiPaginateOption,
) (*XunjiPageList, error) {

	pager, err := newXunjiPager(opts)
	if err != nil {
		return nil, err
	}

	if x, err = pager.ApplyFilter(x); err != nil {
		return nil, err
	}

	ret := &XunjiPageList{}

	ret.PageDetails = &PageDetails{
		Page: pageNum,
		Size: pageSize,
	}

	query := x.Clone()
	query.ctx.Fields = nil
	count, err := query.Count(ctx)

	if err != nil {
		return nil, err
	}

	ret.PageDetails.Total = uint64(count)

	if pager.Order != nil {
		x = x.Order(pager.Order)
	} else {
		x = x.Order(DefaultXunjiOrder)
	}

	x = x.Offset(int((pageNum - 1) * pageSize)).Limit(int(pageSize))
	list, err := x.All(ctx)
	if err != nil {
		return nil, err
	}
	ret.List = list

	return ret, nil
}
