package model

import (
	model2 "cold-delivery/common/model"
	coreModel "gogs.baozhida.cn/zoie/OAuth-core/model"

	"errors"
	"gorm.io/gorm"
)

type SysRole struct {
	model2.Model
	coreModel.Role
	MenuIds []int `json:"menuIds" gorm:"-"`
	model2.ControlBy
	model2.ModelTime
	model2.DeptBy
}

func (SysRole) TableName() string {
	return "sys_role"
}

func (e *SysRole) Generate() model2.ActiveRecord {
	o := *e
	return &o
}

func (e *SysRole) GetId() interface{} {
	return e.Id
}

var (
	ErrForbidUpdateSysRole = errors.New("禁止修改系统角色")
	ErrForbidDeleteSysRole = errors.New("禁止删除系统角色")
)

func (e *SysRole) BeforeDelete(_ *gorm.DB) (err error) {
	if e.RoleKey == "admin" {
		return ErrForbidDeleteSysRole
	}
	return
}

func (e *SysRole) BeforeUpdate(_ *gorm.DB) (err error) {
	if e.RoleKey == "admin" {
		return ErrForbidUpdateSysRole
	}
	return
}
