package request

import (
	"gorm.io/gorm"
)

// PageInfo Paging common input parameter structure
type PageInfo struct {
	Current  int    `json:"current" form:"current"`   // 页码
	PageSize int    `json:"pageSize" form:"pageSize"` // 每页大小
	Keyword  string `json:"keyword" form:"keyword"`   // 关键字
}

func (r *PageInfo) Paginate() func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if r.Current <= 0 {
			r.Current = 1
		}
		switch {
		case r.PageSize > 100:
			r.PageSize = 100
		case r.PageSize <= 0:
			r.PageSize = 10
		}
		offset := (r.Current - 1) * r.PageSize
		return db.Offset(offset).Limit(r.PageSize)
	}
}

// GetById Find by id structure
type GetById struct {
	ID string `json:"id" form:"id"` // 主键ID
}

func (r *GetById) Uint() string {
	return string(r.ID)
}

type IdsReq struct {
	Ids []string `json:"ids" form:"ids"`
}

// GetAuthorityId Get role by id structure
type GetAuthorityId struct {
	AuthorityId string `json:"authorityId" form:"authorityId"` // 角色ID
}

type Empty struct{}

type UploadOss struct {
	Id     string   `json:"id" binding:"required"`     //数据主键
	OssIds []string `json:"ossIds" binding:"required"` // ossIds
}

type DeleteOss struct {
	Id     string   `json:"id" binding:"required"` //数据主键
	OssIds []string `json:"ossIds" binding:"required"`
}

type UploadFile struct {
	Id    string `json:"id" binding:"required"`     //数据主键
	OssId string `json:"ossIds" binding:"required"` // ossId
}
