package models

import (
	"github.com/golang-jwt/jwt/v4"
	"time"
)

type Account struct {
	ID               string `json:"id"`
	Email            string `json:"email"`
	FirstName        string `json:"firstName,omitempty"`
	LastName         string `json:"lastName,omitempty"`
	VerifiedIdentity *bool  `json:"verifiedIdentity,omitempty"`
	BirthDate        string `json:"birthdate,omitempty"`
	Type             string `json:"type,omitempty"`
	LocalCredentials
}

type User struct {
	ID        string `json:"user_id"`
	Status    string `json:"status"`
	BookingID string `json:"booking_id"`
}

type LocalCredentials struct {
	Email                     string
	EmailVerified             bool
	EmailValidationCode       string
	PhoneNumber               string
	PhoneNumberVerified       bool
	PhoneNumberValidationCode string
}

type UserClaims struct {
	jwt.RegisteredClaims
}

func (account Account) CreateToken(ttl time.Duration, key string) (token string, err error) {
	expires_at := jwt.NewNumericDate(time.Now().Add(ttl))
	claims := UserClaims{
		RegisteredClaims: jwt.RegisteredClaims{
			Subject:   account.ID,
			ExpiresAt: expires_at,
		},
	}

	t := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	return t.SignedString([]byte(key))
}
