package forms

import (
	"errors"
	"gadmin/internal/gorm/model"
)

type DictItem struct {
	Key string `json:"name"`
	Val int32  `json:"code"`
	Id  int32  `json:"id"`
}

type CateDictData struct {
	Category string     `json:"category"`
	Items    []DictItem `json:"items"`
}

type DictRespData struct {
	Code int32          `json:"code"`
	Data []CateDictData `json:"data"`
}

// dict字典end

// loginlog
type LoginlogReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	EventId   int32  `form:"eventId"`
	UserType  int32  `form:"userType"`
	Day       string `form:"day"`
	Page      int    `form:"page"`
	PerPage   int    `form:"perPage"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

type LoginEventData struct {
	Key       int64  `json:"key"`
	EventId   int64  `json:"event_id"`   // 事件id
	EventName string `json:"event_name"` // 事件名称
	UserCount int64  `json:"user_count"` // 用户数量
	Count     int64  `json:"count"`      // 事件次数
	Cost      int64  `json:"cost"`       // 耗时均值
}

type LoginEventRespData struct {
	Code int32            `json:"code"`
	Msg  string           `json:"msg"`
	Data []LoginEventData `json:"data"`
}

// 登陆事件end

type UserChapterLogReq struct {
	ChannelId  string `json:"channel_id" form:"channel_id"`
	Day        string `form:"day"`
	Days       int64  `form:"days"`
	ChapterId  int64  `form:"chapter_id"`
	Difficulty int64  `form:"difficulty"`
	ServerId   int    `json:"server_id" form:"server_id"`
	Flag       int32  `json:"flag" form:"flag"`
}

type UserChapterItem struct {
	Id          int   `json:"key"`
	RoomId      int32 `json:"room_id"`
	Count       int32 `json:"count"`
	SettelCount int32 `json:"settle_count"`
}

type UserChapterLogData struct {
	Chapter1 []UserChapterItem `json:"chapter1"`
	Chapter2 []UserChapterItem `json:"chapter2"`
	Chapter3 []UserChapterItem `json:"chapter3"`
}

type UserChapterLogRespData struct {
	Code int32             `json:"code"`
	Data []UserChapterItem `json:"data"`
}

// 关卡数据end

// 死亡数据
type DieDataReq struct {
	ListReq
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
}

type DieInfoItem struct {
	Id              int    `json:"key"`
	Index           int    `json:"index"`
	ChapterId       int    `json:"chapter_id"`
	Chapter         string `json:"chapter"`
	DifficultyIndex int    `json:"difficulty_index"`
	Difficulty      string `json:"difficulty"`
	DieCount        int    `json:"die_count"`
	DieUserCount    int    `json:"die_user_count"`
	NewDieCount     int    `json:"new_die_count"`
	NewDieUserCount int    `json:"new_die_user_count"`
}

type DieRespData struct {
	ListRes
}

type DieInfoItemSlice []DieInfoItem

func (p DieInfoItemSlice) Len() int {
	return len(p)
}

func (p DieInfoItemSlice) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p DieInfoItemSlice) Less(i, j int) bool {
	return p[j].Index > p[i].Index
}

// 死亡数据 end

type ConditionItem struct {
	Id          int32  `json:"key"`
	ConditionId int32  `json:"condition_id"`
	Name        string `json:"name"`
	Val         int    `json:"val"`
}

type BasicInfoReq struct {
	Day      string `form:"day"`
	ServerId int    `json:"server_id" form:"server_id"`
}

type BasicInfoItem struct {
	ID    int    `json:"key"`
	Name  string `json:"name"`
	Count int64  `json:"count"`
}

type BasicRespData struct {
	Code int32           `json:"code"`
	Msg  string          `json:"msg"`
	Data []BasicInfoItem `json:"data"`
}

type BasicReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Page      int64  `json:"page" form:"page"`
	PerPage   int64  `json:"pageSize"  form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
	IsExport  int    `json:"is_export" form:"is_export"`
}

type BasicReportItem struct {
	ID             int64  `json:"key"`
	Date           string `json:"date"`
	OldCount       int64  `json:"old_count"`
	NewCount       int64  `json:"new_count"`
	ActiveCount    int64  `json:"active_count"`
	ValidCount     int64  `json:"valid_count"`
	NewDuration    int64  `json:"new_duration"`
	ValidDuration  int64  `json:"valid_duration"`
	ActiveDuration int64  `json:"active_duration"`
	Day1Active     int64  `json:"day_1_active"`
	Day2Active     int64  `json:"day_2_active"`
	Day3Active     int64  `json:"day_3_active"`
	Day4Active     int64  `json:"day_4_active"`
	Day5Active     int64  `json:"day_5_active"`
	Day6Active     int64  `json:"day_6_active"`
	Day7Active     int64  `json:"day_7_active"`
	Day14Active    int64  `json:"day_14_active"`
	Day30Active    int64  `json:"day_30_active"`
}

type BasicReportRespData struct {
	Code  int32             `json:"code"`
	Msg   string            `json:"msg"`
	Data  []BasicReportItem `json:"data"`
	Total int64             `json:"total"`
}

type ConditionReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Page      int64  `json:"page" form:"page"`
	PerPage   int64  `json:"pageSize"  form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
}

type ConditionReportItem struct {
	ID                 int64  `json:"key"`
	ConditionId        int64  `json:"condition_id"`
	Name               string `json:"name"`
	Date               string `json:"date"`
	GuideFinishedCount int64  `json:"guideFinishedCount"`
	NewCount           int64  `json:"count"`
	Day1Active         int64  `json:"day_1_active"`
	Day2Active         int64  `json:"day_2_active"`
	Day3Active         int64  `json:"day_3_active"`
	Day4Active         int64  `json:"day_4_active"`
	Day5Active         int64  `json:"day_5_active"`
	Day6Active         int64  `json:"day_6_active"`
	Day7Active         int64  `json:"day_7_active"`
	Day14Active        int64  `json:"day_14_active"`
	Day30Active        int64  `json:"day_30_active"`
}

type ConditionReportRespData struct {
	Code  int32                 `json:"code"`
	Msg   string                `json:"msg"`
	Data  []ConditionReportItem `json:"data"`
	Total int64                 `json:"total"`
}

// 基础用户数据 end

// QueryAdvEchartsReq 广告点位折线
type QueryAdvEchartsReq struct {
	ChannelId  string `json:"channel_id" form:"channel_id"`
	PositionId int64  `form:"position_id"`
	Day        string `form:"day"`
	EndDay     string `form:"endDay"`
	ServerId   int    `json:"server_id" form:"server_id"`
}

// adv
type AdvReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
}

type AdvReportItem struct {
	ID          int64 `json:"key"`
	PositionId  int64 `json:"position_id"`
	ShowTimes   int64 `json:"show_times"`
	ClickTimes  int64 `json:"click_times"`
	RewardTimes int64 `json:"reward_times"`
	ShowUsers   int64 `json:"show_users"`
	ClickUsers  int64 `json:"click_users"`
	RewardUsers int64 `json:"reward_users"`
}

type AdvReportRespData struct {
	Code  int32           `json:"code"`
	Msg   string          `json:"msg"`
	Data  []AdvReportItem `json:"data"`
	Total int64           `json:"total"`
}

type AdvDetailsReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`  // 哪一天的数据
	Days      string `form:"days"` // 首日为0,昨日为1,前天为2
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
}

type AdvUserDetailsReq struct {
	UserId  int64   `json:"user_id" form:"user_id"`
	EventAt []int64 `json:"event_at" form:"event_at[]"`
}

func (req *AdvUserDetailsReq) 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
}

type AdvUserReportItem struct {
	ID          int64 `json:"key"`
	PositionId  int64 `json:"position_id"`
	ShowTimes   int64 `json:"show_times"`
	ClickTimes  int64 `json:"click_times"`
	RewardTimes int64 `json:"reward_times"`
}

type AdvUserReportRespData struct {
	Code  int32                `json:"code"`
	Msg   string               `json:"msg"`
	Data  []*AdvUserReportItem `json:"data"`
	Total int64                `json:"total"`
}

type FirstAdvReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Page      int64  `json:"page" form:"page"`
	PerPage   int64  `json:"pageSize"  form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

type FirstAdvRespData struct {
	Code  int32          `json:"code"`
	Msg   string         `json:"msg"`
	Data  []FirstAdvItem `json:"data"`
	Total int64          `json:"total"`
}

type FirstAdvItem struct {
	ID       int64  `json:"key"`
	Date     string `json:"date"`
	Goto     int64  `json:"goto"`
	A        int64  `json:"a"`
	B        int64  `json:"b"`
	C        int64  `json:"c"`
	Waive    int64  `json:"waive"`
	EquipNow int64  `json:"equipNow"`
}

type AdvSummReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Page      int64  `json:"page" form:"page"`
	PerPage   int64  `json:"pageSize"  form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
	IsExport  int32  `json:"is_export" form:"is_export"`
}

type AdvSummRespData struct {
	Code  int32         `json:"code"`
	Msg   string        `json:"msg"`
	Data  []AdvSummItem `json:"data"`
	Total int64         `json:"total"`
}

type AdvSummItem struct {
	ID          int64  `json:"key"`
	Date        string `json:"date"`
	RewardTimes int64  `json:"rewardTimes"`
	RewardUsers int64  `json:"rewardUsers"`
	NewTimes    int64  `json:"newTimes"`
	NewUsers    int64  `json:"newUsers"`
	OldTimes    int64  `json:"oldTimes"`
	OldUsers    int64  `json:"oldUsers"`

	// 人数相关
	ActiveCount int64 `json:"activeCount"`
	NewCount    int64 `json:"newCount"`
	OldCount    int64 `json:"oldCount"`
}

type GradeDistributionReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
}

type GoodsReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
}

type GoodsReportItem struct {
	ID           int64  `json:"key"`
	PositionId   int64  `json:"position_id"`
	GoodsId      int64  `json:"goods_id"`
	ShowTimes    int64  `json:"show_times"`
	ClickTimes   int64  `json:"click_times"`
	SuccessTimes int64  `json:"success_times"`
	ShowUsers    int64  `json:"show_users"`
	ClickUsers   int64  `json:"click_users"`
	SuccessUsers int64  `json:"success_users"`
	Comment      string `json:"comment"`
}

type GoodsReportRespData struct {
	Code  int32             `json:"code"`
	Msg   string            `json:"msg"`
	Data  []GoodsReportItem `json:"data"`
	Total int64             `json:"total"`
}

// QueryBasicRetentionReq 查询基础留存率
type QueryBasicRetentionReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	ServerId  int    `json:"server_id" form:"server_id"`
	Flag      int32  `json:"flag" form:"flag"`
}

// adv end

// ExpeditionReportReq 统计远征信息
type ExpeditionReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

// ExpeditionFloorReq 远征关卡未通关信息
type ExpeditionFloorReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

// DuelReportReq 狭路对决远征信息
type DuelReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

// IdiomReportReq 金榜题名报表
type IdiomReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

// BossReportReq 暗影突袭报表
type BossReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

type HeroLevelDistributedReq struct {
	ChannelId  string `json:"channel_id" form:"channel_id"`
	Day        string `form:"day"`
	StartLevel int    `form:"startLevel"`
	EndLevel   int    `form:"endLevel"`
	ServerId   int    `json:"server_id" form:"server_id"`
}

type HeroLevelDistributedRespData struct {
	HeroName []string                    `json:"heroName""`
	Level    []string                    `json:"level"`
	Data     []*HeroLevelDistributedItem `json:"data""`
}

type HeroLevelDistributedItem struct {
	Data []int  `json:"data""`
	Type string `json:"type""`
	Name string `json:"name""`
}

// SevenBasicReq 七日任务基础信息
type SevenBasicReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Page      int64  `json:"page" form:"page"`
	PerPage   int64  `json:"pageSize"  form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

type SevenBasicItem struct {
	ID              int64  `json:"id"`
	Date            string `json:"date"`
	PlayerCount     int64  `json:"player_count"`
	ValidCount      int64  `json:"valid_count"`
	NewPlayerCount  int64  `json:"new_player_count"`
	OpenCount       int64  `json:"open_count"`
	AllTaskSucCount int64  `json:"all_task_suc_count"`
	Unlock1         int64  `json:"unlock1"`
	Unlock2         int64  `json:"unlock2"`
	Unlock3         int64  `json:"unlock3"`
	Unlock4         int64  `json:"unlock4"`
	Unlock5         int64  `json:"unlock5"`
	Unlock6         int64  `json:"unlock6"`
	Unlock7         int64  `json:"unlock7"`
}

type SevenBasicRespData struct {
	Code  int32            `json:"code"`
	Msg   string           `json:"msg"`
	Data  []SevenBasicItem `json:"data"`
	Total int64            `json:"total"`
}

// SevenTaskReq 七日任务任务统计
type SevenTaskReq struct {
	Day      string `form:"day"`
	EndDay   string `form:"endDay"`
	Page     int64  `json:"page" form:"page"`
	PerPage  int64  `json:"pageSize"  form:"pageSize"`
	ServerId int    `json:"server_id" form:"server_id"`
}

type SevenTaskItem struct {
	ID            int64   `json:"id"`
	TaskID        int64   `json:"taskId"`
	Describe      string  `json:"describe"`
	DayValue      int64   `json:"dayValue"`
	SucCount      int64   `json:"sucCount"`
	FirstSucCount int64   `json:"firstSucCount"`
	AdvSucDays    float64 `json:"advSucDays"`
}

type SevenTaskRespData struct {
	Code  int32            `json:"code"`
	Msg   string           `json:"msg"`
	Data  []*SevenTaskItem `json:"data"`
	Total int64            `json:"total"`
}

// SevenAwardReq 七日任务奖励统计
type SevenAwardReq struct {
	Day      string `form:"day"`
	EndDay   string `form:"endDay"`
	Page     int64  `json:"page" form:"page"`
	PerPage  int64  `json:"pageSize"  form:"pageSize"`
	ServerId int    `json:"server_id" form:"server_id"`
}

type SevenAwardItem struct {
	ID            int64   `json:"id"`
	TaskID        int64   `json:"taskId"`
	Describe      string  `json:"describe"`
	DayValue      int64   `json:"dayValue"`
	SucCount      int64   `json:"sucCount"`
	FirstSucCount int64   `json:"firstSucCount"`
	AdvSucDays    float64 `json:"advSucDays"`
}

type SevenAwardRespData struct {
	Code  int32             `json:"code"`
	Msg   string            `json:"msg"`
	Data  []*SevenAwardItem `json:"data"`
	Total int64             `json:"total"`
}

// DisconnectListReq 断线重连统计
type DisconnectListReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int64  `json:"page" form:"page"`
	PerPage   int64  `json:"pageSize"  form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

type DisconnectListItem struct {
	ID            int32   `json:"id"`
	TaskID        int64   `json:"taskId"`
	Describe      string  `json:"describe"`
	DayValue      int64   `json:"dayValue"`
	SucCount      int32   `json:"sucCount"`
	FirstSucCount int32   `json:"firstSucCount"`
	AdvSucDays    float64 `json:"advSucDays"`
}

type DisconnectListRes struct {
	Code  int32                        `json:"code"`
	Msg   string                       `json:"msg"`
	Data  []*model.ReportDayDisconnect `json:"data"`
	Total int64                        `json:"total"`
}

// GemReportReq 宝石报表
type GemReportReq struct {
	ChannelId string `json:"channel_id" form:"channel_id"`
	Day       string `form:"day"`
	EndDay    string `form:"endDay"`
	Page      int    `form:"page"`
	PerPage   int    `form:"pageSize"`
	ServerId  int    `json:"server_id" form:"server_id"`
}

// GemStatReq 宝石统计
type GemStatReq struct {
	ServerId int `json:"server_id" form:"server_id"`
}

// GemPartStatReq 部位宝石统计
type GemPartStatReq struct {
	ServerId int `json:"server_id" form:"server_id"`
}

// LevelOutputReq 等级产出
type LevelOutputReq struct {
	ChannelId  string `json:"channel_id" form:"channel_id"`
	StartLevel int32  `form:"startLevel"`
	EndLevel   int32  `form:"endLevel"`
	Page       int    `form:"page"`
	PerPage    int    `form:"pageSize"`
	ServerId   int    `json:"server_id" form:"server_id"`
}
