package models

import (
	"time"
)

// Account - Account table struct
type Account struct {
	ID       string    `xorm:"id"`
	Account  string    `xorm:"account"`
	Password string    `xorm:"password"`
	Nick     string    `xorm:"nick"`
	Email    string    `xorm:"email"`
	Ctime    time.Time `xorm:"ctime"`
	Mtime    time.Time `xorm:"mtime"`
}

// GetAllAccount - all account
func GetAllAccount() ([]Account, error) {
	var accs []Account
	err := x.Table("account").Find(&accs)
	return accs, err
}

// GetAccount -
func GetAccount(account string) (acc *Account, err error) {
	acc = &Account{
		Account: account,
	}
	ok, err := x.Table("account").Get(acc)
	if err != nil {
		return nil, err
	}
	if !ok {
		return nil, nil
	}

	return
}
