package forms

import (
	"gadmin/internal/admin/consts"
)

type ListReq struct {
	Page    int64 `json:"page" form:"page"`
	PerPage int64 `json:"pageSize" form:"pageSize"`
}
type ListRes struct {
	Page      int64       `json:"page" form:"page"`
	PerPage   int64       `json:"pageSize" form:"pageSize"`
	PageCount int64       `json:"pageCount" form:"pageCount"`
	List      interface{} `json:"list" form:"list"`
}

type SorterModel struct {
	Field string `json:"field" form:"field"`
	By    string `json:"by" form:"by"`
}

func CalculatePage(page, perPage int64) (newPage, newPerPage int64, offset int64) {
	if page <= 0 {
		newPage = consts.FormsDefaultPage
	} else {
		newPage = page
	}
	if perPage <= 0 {
		newPerPage = consts.FormsDefaultPageSize
	} else {
		newPerPage = perPage
	}

	offset = (newPage - 1) * newPerPage
	return
}

type GetReq struct {
	Id int `json:"id" form:"id"`
}

type SaveReq struct {
	Id int `json:"id" form:"id"`
}

type DeleteReq struct {
	Id int `json:"id" form:"id"`
}

type PlayeridReq struct {
	Playerid int64 `form:"playerid" json:"playerid" binding:"required"`
}

type JsonResource struct {
	Version string `json:"version" form:"version" binding:"required"`
	Name    string `json:"name" form:"name" binding:"required"`
}

type Counter struct {
	Total int64 `json:"total"`
}

type CounterF struct {
	Total float64 `json:"total"`
}

type Checker interface {
	Check() error
}

func ParseParams(req interface{}) error {
	if c, ok := req.(Checker); ok {
		return c.Check()
	}
	return nil
}

type Option struct {
	Value interface{} `json:"value"`
	Label string      `json:"label"`
	Name  string      `json:"name"`
}

type OptionInt64 struct {
	Value int64  `json:"value"`
	Label string `json:"label"`
	Name  string `json:"name"`
}

type TreeOption struct {
	Key      interface{}   `json:"key"`
	Label    string        `json:"label"`
	Children []*TreeOption `json:"children,omitempty"`
}
