package schema

import (
	"juwan-backend/pkg/types"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect"
	"entgo.io/ent/schema/field"
)

// Users holds the schema definition for the Users entity.
type Users struct {
	ent.Schema
}

type VerificationStatusStruct struct {
	Player   string `json:"player" validate:"oneof:pending rejected approved"`
	Owner    string `json:"owner" validate:"oneof:pending rejected approved"`
	Consumer string `json:"consumer" validate:"oneof:pending rejected approved"`
}

// Fields of the Users.
func (Users) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id").Unique().Immutable(),
		field.String("username").Unique(),
		field.String("password_hash"),
		field.String("email").Unique(),
		field.String("phone").Unique(),
		field.String("nickname").Default(""),
		field.String("avatar").Default(""),
		field.String("bio").Default(""),
		field.String("current_role").Default("consumer").NotEmpty(),
		//field.Strings("verified_roles").Default([]string{"consumer"}),
		field.JSON("verificationStatus", VerificationStatusStruct{}).Optional(),
		field.Bool("is_admin").Default(false),
		field.Time("created_at").Default(time.Now),
		field.Time("updated_at").Default(time.Now),
		field.Time("deleted_at").Optional(),
		field.Other("verified_roles", types.TextArray{}).
			SchemaType(map[string]string{dialect.Postgres: "text[]"}).Optional(),
	}
}

// Edges of the Users.
func (Users) Edges() []ent.Edge {
	return nil
}
