package forms

import (
	"errors"
)

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

type PlayerAttrGetAllReq struct {
	AccId int64 `form:"accId" json:"accId" binding:"required"`
}

type LevelRankingReq struct {
	ListReq
	ServerId int `json:"server_id" form:"server_id"`
}

func (req *LevelRankingReq) Check() error {
	if req.ServerId <= 0 {
		return errors.New("请选择一个有效的服务器")
	}
	return nil
}

type AdvRankingReq struct {
	ListReq
	ServerId   int     `json:"server_id" form:"server_id"`
	Createtime []int64 `json:"createtime" form:"createtime[]"`
}

func (req *AdvRankingReq) Check() error {
	//if req.ServerId <= 0 {
	//	return errors.New("请选择一个有效的服务器")
	//}
	if req.Createtime != nil && len(req.Createtime) != 2 {
		return errors.New("时间必须选择一个区间或者留空")
	}

	if len(req.Createtime) == 2 {
		if req.Createtime[0] > req.Createtime[1] {
			return errors.New("时间选择的区间值不合理")
		}

		// 默认是毫秒
		req.Createtime[0] = req.Createtime[0] / 1000
		req.Createtime[1] = req.Createtime[1] / 1000
	}
	return nil
}

type LoginRankingReq struct {
	ListReq
	ServerId   int     `json:"server_id" form:"server_id"`
	Createtime []int64 `json:"createtime" form:"createtime[]"`
}

func (req *LoginRankingReq) Check() error {
	//if req.ServerId <= 0 {
	//	return errors.New("请选择一个有效的服务器")
	//}
	//if req.Createtime != nil && len(req.Createtime) != 2 {
	//	return errors.New("时间必须选择一个区间或者留空")
	//}

	if len(req.Createtime) != 2 {
		return errors.New("必须选择一个时间区间")
	}

	if len(req.Createtime) == 2 {
		if req.Createtime[0] > req.Createtime[1] {
			return errors.New("时间选择的区间值不合理")
		}

		// 默认是毫秒
		req.Createtime[0] = req.Createtime[0] / 1000
		req.Createtime[1] = req.Createtime[1] / 1000
	}
	return nil
}

type LoginLogListReq struct {
	ListReq
	Id     int64 `json:"id" form:"id"`
	UserId int64 `json:"user_id" form:"playerId"`
	//ChapterId  int32   `json:"chapter_id" form:"chapter_id"`
	//Difficulty int32   `json:"difficulty" form:"difficulty"`
	EventAt []int64 `json:"event_at" form:"event_at[]"`
}

func (req *LoginLogListReq) Check() error {

	if req.EventAt != nil && len(req.EventAt) != 2 {
		return errors.New("时间必须选择一个区间或者留空")
	}

	if len(req.EventAt) == 2 {
		if req.EventAt[0] > req.EventAt[1] {
			return errors.New("时间选择的区间值不合理")
		}

		// 默认是毫秒
		req.EventAt[0] = req.EventAt[0] / 1000
		req.EventAt[1] = req.EventAt[1] / 1000
	}

	return nil
}
