package models

import "time"

// User represents a system user (SuperAdmin, CompanyAdmin, Recruiter, or JobSeeker)
type User struct {
	ID           int    `json:"id" db:"id"`
	Identifier   string `json:"identifier" db:"identifier"`
	PasswordHash string `json:"-" db:"password_hash"` // Never expose password hash in JSON
	Role         string `json:"role" db:"role"`       // superadmin, companyAdmin, recruiter, jobSeeker

	// Personal Info
	FullName  string  `json:"fullName" db:"full_name"`
	Phone     *string `json:"phone,omitempty" db:"phone"`
	LineID    *string `json:"lineId,omitempty" db:"line_id"`
	WhatsApp  *string `json:"whatsapp,omitempty" db:"whatsapp"`
	Instagram *string `json:"instagram,omitempty" db:"instagram"`

	// Settings
	Language string `json:"language" db:"language"` // pt, en, es, ja
	Active   bool   `json:"active" db:"active"`

	// Metadata
	CreatedAt   time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt   time.Time  `json:"updatedAt" db:"updated_at"`
	LastLoginAt *time.Time `json:"lastLoginAt,omitempty" db:"last_login_at"`
}

// UserResponse is the public representation of a user (without sensitive data)
type UserResponse struct {
	ID          int        `json:"id"`
	Identifier  string     `json:"identifier"`
	Role        string     `json:"role"`
	FullName    string     `json:"fullName"`
	Phone       *string    `json:"phone,omitempty"`
	LineID      *string    `json:"lineId,omitempty"`
	WhatsApp    *string    `json:"whatsapp,omitempty"`
	Instagram   *string    `json:"instagram,omitempty"`
	Language    string     `json:"language"`
	Active      bool       `json:"active"`
	CreatedAt   time.Time  `json:"createdAt"`
	LastLoginAt *time.Time `json:"lastLoginAt,omitempty"`
}

// ToResponse converts User to UserResponse
func (u *User) ToResponse() UserResponse {
	return UserResponse{
		ID:          u.ID,
		Identifier:  u.Identifier,
		Role:        u.Role,
		FullName:    u.FullName,
		Phone:       u.Phone,
		LineID:      u.LineID,
		WhatsApp:    u.WhatsApp,
		Instagram:   u.Instagram,
		Language:    u.Language,
		Active:      u.Active,
		CreatedAt:   u.CreatedAt,
		LastLoginAt: u.LastLoginAt,
	}
}
