package entities

import (
	"errors"

	"github.com/google/uuid"
)

const UserTable = "users"

type User struct {
	Id       uuid.UUID `db:"id"`
	UserName string    `db:"username"`
	Password string    `db:"password"`
}

func CreateUser(userName string, password string) (user User, err error) {
	user = User{
		Id:       uuid.New(),
		UserName: userName,
		Password: password,
	}

	err = user.Validate()

	return
}

func (u *User) Validate() error {
	if err := uuid.Validate(u.Id.String()); err != nil {
		return errors.New("Invalid user.id")
	}
	if u.UserName == "" {
		return errors.New("Empty user.name")
	}

	if u.Password == "" {
		return errors.New("Empty user.password")
	}

	return nil
}
