package model

import "time"

type Role struct {
	ID          uint64     `gorm:"primaryKey" json:"id"`
	Code        string     `gorm:"size:64;not null;uniqueIndex" json:"code"`
	Name        string     `gorm:"size:64;not null" json:"name"`
	Description string     `gorm:"size:255;not null;default:''" json:"description"`
	CreatedAt   time.Time  `json:"created_at"`
	UpdatedAt   time.Time  `json:"updated_at"`
}

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

type Permission struct {
	ID        uint64    `gorm:"primaryKey" json:"id"`
	Code      string    `gorm:"size:128;not null;uniqueIndex" json:"code"`
	Name      string    `gorm:"size:64;not null" json:"name"`
	Resource  string    `gorm:"size:128;not null" json:"resource"`
	Action    string    `gorm:"size:64;not null" json:"action"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (Permission) TableName() string { return "permissions" }

type AdminUserRole struct {
	ID         uint64    `gorm:"primaryKey" json:"id"`
	AdminID    uint64    `gorm:"column:admin_user_id;not null;uniqueIndex:uk_admin_user_roles_user_role" json:"admin_id"`
	RoleID     uint64    `gorm:"column:role_id;not null;uniqueIndex:uk_admin_user_roles_user_role" json:"role_id"`
	CreatedAt  time.Time `json:"created_at"`
}

func (AdminUserRole) TableName() string { return "admin_user_roles" }

type RolePermission struct {
	ID           uint64    `gorm:"primaryKey" json:"id"`
	RoleID       uint64    `gorm:"column:role_id;not null;uniqueIndex:uk_role_permissions_role_permission" json:"role_id"`
	PermissionID uint64    `gorm:"column:permission_id;not null;uniqueIndex:uk_role_permissions_role_permission" json:"permission_id"`
	CreatedAt    time.Time `json:"created_at"`
}

func (RolePermission) TableName() string { return "role_permissions" }
