/*
 * @Descripttion:
 * @version:
 * @Author: Neo,Huang
 * @Date: 2020-03-17 13:54:11
 * @LastEditors: Neo,Huang
 * @LastEditTime: 2020-10-23 13:44:43
 */
package models

const (
	ModelUser     = 0
	ModelStatment = 1
	ModelRealTime = 2
	ModelSystem   = 3
	ModelRoll     = 4
)

// 权限信息，新增大功能需要新增权限
type PermissionInfo struct {
	Id   int    `form:"id"`
	Name string `form:"name"`
}

// IndexInfo 界面信息，每新增一个功能都要新增该结构
type IndexInfo struct {
	Id   int    //界面id，模板文件中会使用到这个id，作为焦点
	Name string //界面在导航中的显示名
	Url  string //界面的url地址
}
type NavInfo struct {
	Id        int //界面id，模板文件中会使用到这个id，作为焦点
	Name      string
	IndexList []*IndexInfo
}

func GetPermissions() []*PermissionInfo {
	var perList []*PermissionInfo
	navList := GetNavList(GetPermission("admin"))
	for _, v := range navList {
		perList = append(perList, &PermissionInfo{
			Id:   v.Id,
			Name: v.Name,
		})
	}
	return perList
}

func GetNavList(permission int64) []*NavInfo {
	var navList []*NavInfo
	if (permission & (1 << uint(ModelUser))) != 0 {
		navInfo := &NavInfo{
			Id:   ModelUser,
			Name: "系统",
		}
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelUser,
			Name: "用户管理",
			Url:  "user.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelUser,
			Name: "角色管理",
			Url:  "role.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelUser,
			Name: "日志管理",
			Url:  "log.html",
		})

		navList = append(navList, navInfo)
	}
	if (permission & (1 << uint(ModelStatment))) != 0 {
		navInfo := &NavInfo{
			Id:   ModelStatment,
			Name: "统计数据",
		}
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "统计注册",
			Url:  "register.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "统计留存",
			Url:  "retained.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "统计登录",
			Url:  "login.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "在线时长",
			Url:  "onlinetime.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "玩家资源",
			Url:  "resource.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "统计支付金额",
			Url:  "pay.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "统计商品",
			Url:  "goods.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "付费人数",
			Url:  "paynum.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "订单查询",
			Url:  "orderquery.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelStatment,
			Name: "客户端埋点",
			Url:  "client.html",
		})

		navList = append(navList, navInfo)
	}
	if (permission & (1 << uint(ModelRealTime))) != 0 {
		navInfo := &NavInfo{
			Id:   ModelRealTime,
			Name: "实时数据",
		}
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelRealTime,
			Name: "实时注册",
			Url:  "rtregister.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelRealTime,
			Name: "实时登录",
			Url:  "rtlogin.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelRealTime,
			Name: "实时在线",
			Url:  "rtonline.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelRealTime,
			Name: "实时支付金额",
			Url:  "rtpay.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelRealTime,
			Name: "实时支付登录",
			Url:  "rtpaylogin.html",
		})

		navList = append(navList, navInfo)
	}
	if (permission & (1 << uint(ModelSystem))) != 0 {
		navInfo := &NavInfo{
			Id:   ModelSystem,
			Name: "游戏系统设置",
		}
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelSystem,
			Name: "版本更新",
			Url:  "hotfix.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelSystem,
			Name: "兑换码",
			Url:  "exchangecode.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelSystem,
			Name: "配置管理",
			Url:  "gameconfig.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelSystem,
			Name: "Roll奖励方案管理",
			Url:  "rollaward.html",
		})
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelSystem,
			Name: "Roll房管理",
			Url:  "roll.html",
		})

		navList = append(navList, navInfo)
	}
	if (permission & (1 << uint(ModelRoll))) != 0 {
		navInfo := &NavInfo{
			Id:   ModelRoll,
			Name: "Roll房",
		}
		navInfo.IndexList = append(navInfo.IndexList, &IndexInfo{
			Id:   ModelRoll,
			Name: "Roll房管理",
			Url:  "roll.html",
		})

		navList = append(navList, navInfo)
	}

	return navList
}
