package models

import "time"

type UserRecord struct {
	Account         string   `json:"account"`
	PasswordHash    string   `json:"passwordHash"`
	Username        string   `json:"username"`
	Email           string   `json:"email"`
	Level           int      `json:"level"`
	SproutCoins     int      `json:"sproutCoins"`
	SecondaryEmails []string `json:"secondaryEmails,omitempty"`
	Phone           string   `json:"phone,omitempty"`
	AvatarURL       string   `json:"avatarUrl,omitempty"`
	Bio             string   `json:"bio,omitempty"`
	CreatedAt       string   `json:"createdAt"`
	UpdatedAt       string   `json:"updatedAt"`
}

type UserPublic struct {
	Account         string   `json:"account"`
	Username        string   `json:"username"`
	Email           string   `json:"email"`
	Level           int      `json:"level"`
	SproutCoins     int      `json:"sproutCoins"`
	SecondaryEmails []string `json:"secondaryEmails,omitempty"`
	Phone           string   `json:"phone,omitempty"`
	AvatarURL       string   `json:"avatarUrl,omitempty"`
	Bio             string   `json:"bio,omitempty"`
	CreatedAt       string   `json:"createdAt"`
	UpdatedAt       string   `json:"updatedAt"`
}

func (u UserRecord) Public() UserPublic {
	return UserPublic{
		Account:         u.Account,
		Username:    u.Username,
		Email:       u.Email,
		Level:       u.Level,
		SproutCoins:     u.SproutCoins,
		SecondaryEmails: u.SecondaryEmails,
		Phone:           u.Phone,
		AvatarURL:       u.AvatarURL,
		Bio:             u.Bio,
		CreatedAt:       u.CreatedAt,
		UpdatedAt:       u.UpdatedAt,
	}
}

func NowISO() string {
	return time.Now().Format(time.RFC3339)
}
