package config

import (
	"context"
	"gadmin/internal/gorm/model"
	"gadmin/internal/gorm/query"
	"github.com/sirupsen/logrus"
)

var menus = map[string]string{
	"/api/gm/updatePlayerBase":                  "更新玩家金币、钻石、 经验、体力、精力、天赋点",
	"/api/gm/updateChapter":                     "更新玩家关卡信息",
	"/api/gm/updateTalents":                     "更新玩家天赋",
	"/api/gm/updateGuides":                      "更新玩家引导",
	"/api/gm/updateSwitchers":                   "更新苹果支付、广告收益",
	"/api/gm/update_el_rank":                    "更新无尽排行榜",
	"/api/gm/upgradeRole":                       "升级玩家角色",
	"/api/gm/upgrade_role":                      "升级玩家角色2",
	"/api/gm/userRoles":                         "获取用户的角色数量信息",
	"/api/gm/addEquipment":                      "更新玩家装备",
	"/api/gm/addExp":                            "更新玩家经验值",
	"/api/gm/add_equipment":                     "更新玩家装备2",
	"/api/gm/add_material":                      "更新玩家材料",
	"/api/gm/addMaterial":                       "更新玩家材料2",
	"/api/gm/add_rune":                          "更新玩家符文",
	"/api/gm/addStamina":                        "更新玩家体力、精力",
	"/api/gm/addCoin":                           "更新玩家金币、钻石",
	"/api/gm/del_notice":                        "删除广播",
	"/api/gm/delete_player":                     "删除玩家",
	"/api/gm/delete_account":                    "删除玩家账号",
	"/api/gm/delRank":                           "删除排行榜",
	"/api/gm/letters/add":                       "发送邮件",
	"/api/gm/letters/del":                       "删除邮件",
	"/api/gm/msdSettle":                         "米大师结算",
	"/api/gm/tools/restart":                     "重启服务",
	"/api/gm/set_conf_path":                     "修改配置路径",
	"/api/gm/notices":                           "添加广播",
	"/api/gm/openAccount":                       "开通玩家账号登录",
	"/api/gm/editServerDate":                    "修改服务器时间",
	"/api/ranking/clearPVPRank":                 "删除pvp排行榜",
	"/api/ranking/clearCurioRank":               "删除古玩排行榜",
	"/api/ranking/clearIdiomRank":               "删除金榜题名排行榜",
	"/api/ranking/clearBossRank":                "删除boss排行榜",
	"/api/retrofitGroup/edit":                   "修改配装模板",
	"/api/retrofitGroup/delete":                 "删除配装模板",
	"/api/retrofit/edit":                        "修改配装",
	"/api/retrofit/delete":                      "删除配装",
	"/api/deploy/edit":                          "修改部署服务器",
	"/api/deploy/delete":                        "删除部署服务器",
	"/api/deploy/task":                          "提交部署任务 版本发布",
	"/api/deploy/stop":                          "提交停服任务",
	"/api/drainageServer/edit":                  "修改引流服务器",
	"/api/drainageServer/editDisplay":           "修改显示服务器",
	"/api/drainageServer/editWhiteList":         "修改登录白名单",
	"/api/user/login":                           "登录后台",
	"/api/user/logout":                          "退出登录",
	"/api/userAccount/userBan":                  "拉黑玩家",
	"/api/userAccount/singleBanUser":            "拉黑单服玩家",
	"/api/userAccount/banUserChat":              "禁止玩家聊天",
	"/api/userAccount/paySwitch":                "玩家支付开关",
	"/api/admin/roleEdit":                       "修改后台角色",
	"/api/admin/resetPassword":                  "重置管理员密码",
	"/api/admin/userEdit":                       "修改管理员信息",
	"/api/admin/updatePassword":                 "更新登录密码",
	"/api/cdk/add":                              "添加兑换码",
	"/api/cdk/del":                              "删除兑换码",
	"/api/cdk/batchInvalid":                     "批次作废",
	"/api/channel/statEdit":                     "修改渠道标识",
	"/api/notice/add":                           "添加广播",
	"/api/notice/cancel":                        "终止广播",
	"/api/gm/releaseVersion":                    "提审发布",
	"/api/userAccount/updateNickname":           "修改玩家昵称",
	"/api/userAccount/compatibilityTestVerify":  "验证迁移玩家信息",
	"/api/userAccount/compatibilityTestMigrate": "迁移玩家数据",
	"/api/migrate/userInfo":                     "拉取迁移玩家信息",
	"/api/migrate/complete":                     "拉取迁移玩家数据",
	"/api/peripherals/receiveCdk":               "领取周边CDK",
	"/api/email/list":                           "V2邮件列表",
	"/api/email/add":                            "V2邮件新增",
	"/api/email/verify":                         "V2邮件审核",
	"/api/grandmaster/setDanScore":              "修改玩家段位分",
	"/api/gm/abnormalOrderReissue":              "异常订单补发",
	"/api/gm/add_gift":                          "赠送礼包",
	"/api/service/select":                       "系统选择",
	"/api/announcement/add":                     "添加公告",
	"/api/announcement/del":                     "删除公告",
}

func GetMenuName(p string) string {
	q := query.Use(DB).AdminOperation
	operation, err := q.WithContext(context.Background()).Where(q.API.Eq(p)).First()
	if err != nil {
		logrus.Error("GetMenuName", "err", err)
		return ""
	}
	return operation.Name

	//v, ok := menus[p]
	//if ok {
	//	return v
	//}
	//return ""
}

func GetAllOptions() []*model.AdminOperation {
	q := DB.Model(&model.AdminOperation{})
	allOperation := make([]*model.AdminOperation, 0)
	err := q.Find(&allOperation).Error
	if err != nil {
		logrus.Error("GetAllOptions", "err", err)
	}
	return allOperation
}

func HasMenu(p string) bool {
	allOptions := GetAllOptions()
	menus := make(map[string]*model.AdminOperation)
	for _, item := range allOptions {
		menus[item.API] = item
	}
	_, ok := menus[p]
	return ok
}
