package dao

import "server/global"

type SysMenu struct {
	SysBaseMenu
	MenuId      uint                   `json:"menuId" gorm:"comment:菜单ID"`
	AuthorityId uint                   `json:"-" gorm:"comment:角色ID"`
	Children    []SysMenu              `json:"children" gorm:"-"`
	Parameters  []SysBaseMenuParameter `json:"parameters" gorm:"foreignKey:SysBaseMenuID;references:MenuId"`
	Btns        map[string]uint        `json:"btns" gorm:"-"`
}

type SysAuthorityMenu struct {
	MenuId      string `json:"menuId" gorm:"comment:菜单ID;column:sys_base_menu_id"`
	AuthorityId string `json:"-" gorm:"comment:角色ID;column:sys_authority_authority_id"`
}

func (s SysAuthorityMenu) TableName() string {
	return "sys_authority_menus"
}

// TODO:菜单查询

// QueryAuthorityMenuByAuthorityId 查询角色菜单 按角色id
func QueryAuthorityMenuByAuthorityId(authorityId uint) (SysAuthorityMenus []SysAuthorityMenu, err error) {
	err = global.GVA_DB.Where("sys_authority_authority_id = ?", authorityId).Find(&SysAuthorityMenus).Error
	return SysAuthorityMenus, err
}

// QuerySysBaseMenuIdById 查询菜单id 按角色id
func QuerySysBaseMenuIdById(authorityId uint) (menuIds []string, err error) {
	err = global.GVA_DB.Model(&SysAuthorityMenu{}).Where("sys_authority_authority_id = ?", authorityId).Pluck("sys_base_menu_id", &menuIds).Error
	return
}

// TODO:菜单新增
// TODO:菜单修改
// TODO:菜单删除
