package models

import "time"

// StaffAccount — tài khoản thầy cô truy cập management
type StaffAccount struct {
	ID                 uint      `gorm:"primaryKey" json:"id"`
	CreatedAt          time.Time `json:"createdAt"`
	UpdatedAt          time.Time `json:"updatedAt"`
	Email              string    `gorm:"column:email;size:255;not null;uniqueIndex" json:"email"`
	PasswordHash       string    `gorm:"column:password_hash;size:255;not null" json:"-"`
	FullName           string    `gorm:"column:full_name;size:255" json:"fullName"`
	MustChangePassword bool      `gorm:"column:must_change_password;not null;default:true" json:"mustChangePassword"`
	IsActive           bool      `gorm:"column:is_active;not null;default:true" json:"isActive"`
}

func (StaffAccount) TableName() string { return "staff_accounts" }

// EmailDomain — đuôi email được phép đăng ký staff
type EmailDomain struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	Domain    string    `gorm:"column:domain;size:128;not null;uniqueIndex" json:"domain"`
	IsActive  bool      `gorm:"column:is_active;not null;default:true" json:"isActive"`
}

func (EmailDomain) TableName() string { return "email_domains" }

// PasswordResetToken — quên mật khẩu
type PasswordResetToken struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	StaffID   uint      `gorm:"column:staff_id;not null;index" json:"staffId"`
	Token     string    `gorm:"column:token;size:64;not null;uniqueIndex" json:"-"`
	ExpiresAt time.Time `gorm:"column:expires_at;not null" json:"expiresAt"`
	UsedAt    *time.Time `gorm:"column:used_at" json:"usedAt,omitempty"`
}

func (PasswordResetToken) TableName() string { return "password_reset_tokens" }

// ChatMessage — tin nhắn thầy cô ↔ sinh viên
type ChatMessage struct {
	ID          uint       `gorm:"primaryKey" json:"id"`
	CreatedAt   time.Time  `json:"createdAt"`
	StaffID     uint       `gorm:"column:staff_id;not null;index:idx_chat_thread,priority:1" json:"staffId"`
	StudentRkID int64      `gorm:"column:student_rk_id;not null;index:idx_chat_thread,priority:2" json:"studentRkId"`
	SenderRole  string     `gorm:"column:sender_role;size:16;not null" json:"senderRole"` // staff | student
	Body        string     `gorm:"column:body;type:text;not null" json:"body"`
	ReadAt      *time.Time `gorm:"column:read_at" json:"readAt,omitempty"`
}

func (ChatMessage) TableName() string { return "chat_messages" }
