package models

import "time"

// User represents a system user (SuperAdmin, CompanyAdmin, Recruiter, or JobSeeker)
type User struct {
	ID           string `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, admin, recruiter, candidate

	// 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"`

	// Candidate Profile Info
	BirthDate  *time.Time `json:"birthDate,omitempty" db:"birth_date"`
	Address    *string    `json:"address,omitempty" db:"address"`
	City       *string    `json:"city,omitempty" db:"city"`
	State      *string    `json:"state,omitempty" db:"state"`
	ZipCode    *string    `json:"zipCode,omitempty" db:"zip_code"`
	Education  *string    `json:"education,omitempty" db:"education"`
	Experience *string    `json:"experience,omitempty" db:"experience"`
	Skills     []string   `json:"skills,omitempty" db:"skills"`
	Objective  *string    `json:"objective,omitempty" db:"objective"`
	Title      *string    `json:"title,omitempty" db:"title"`
	Bio        *string    `json:"bio,omitempty" db:"bio"`
	AvatarURL  *string    `json:"avatarUrl,omitempty" db:"avatar_url"`

	// 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          string     `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,
	}
}
