package models

import "time"

type UserRole string

const (
	RoleViewer       UserRole = "viewer"
	RoleEditor       UserRole = "editor"
	RolePricingAdmin UserRole = "pricing_admin"
	RoleAdmin        UserRole = "admin"
)

type User struct {
	ID           uint      `gorm:"primaryKey;autoIncrement" json:"id"`
	Username     string    `gorm:"size:100;uniqueIndex;not null" json:"username"`
	Email        string    `gorm:"size:255;uniqueIndex;not null" json:"email"`
	PasswordHash string    `gorm:"size:255;not null" json:"-"`
	Role         UserRole  `gorm:"type:enum('viewer','editor','pricing_admin','admin');default:'viewer'" json:"role"`
	IsActive     bool      `gorm:"default:true" json:"is_active"`
	CreatedAt    time.Time `gorm:"autoCreateTime" json:"created_at"`
	UpdatedAt    time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}

func (User) TableName() string {
	return "qt_users"
}

func (u *User) CanEdit() bool {
	return u.Role == RoleEditor || u.Role == RolePricingAdmin || u.Role == RoleAdmin
}

func (u *User) CanManagePricing() bool {
	return u.Role == RolePricingAdmin || u.Role == RoleAdmin
}

func (u *User) CanManageUsers() bool {
	return u.Role == RoleAdmin
}
