package model

import (
	"gorm.io/gorm"
	"time"
)

type Role struct {
	ID        uint           `json:"id" gorm:"primary_key"`
	RoleId    string         `json:"role_id" gorm:"index"`
	Name      string         `json:"name"`
	ParentId  uint           `json:"parent_id"`
	Children  []*Role        `json:"children" gorm:"foreignkey:ParentId"`
	Menu      []*Menu        `json:"menu" gorm:"many2many:role_menus;foreignKey:ID"`
	User      []*User        `json:"user" gorm:"many2many:user_role;foreignkey:RoleId;references:UserId"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

func (Role) TableName() string {
	return "roles"
}
