package domain

const (
	DefaultPageSize = 10
	MaxPageSize     = 50
)

type PageInfo struct {
	Page       int   `json:"page"`
	PageSize   int   `json:"pageSize"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"totalPages"`
}

func NormalizePage(page, pageSize int) PageInfo {
	if page < 1 {
		page = 1
	}
	if pageSize < 1 {
		pageSize = DefaultPageSize
	}
	if pageSize > MaxPageSize {
		pageSize = MaxPageSize
	}
	return PageInfo{Page: page, PageSize: pageSize}
}

func (p PageInfo) WithTotal(total int64) PageInfo {
	p.Total = total
	if total > 0 {
		p.TotalPages = int((total + int64(p.PageSize) - 1) / int64(p.PageSize))
	}
	return p
}

type RunFilter struct {
	OwnerUID int64
	BrandID  string
	Mode     string
	Page     int
	PageSize int
}

type RunPage struct {
	Items      []*Run
	Pagination PageInfo
}

type RunPostPage struct {
	Run        *Run
	Items      []*Post
	Pagination PageInfo
}
