You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.2 KiB
Go

package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// GameSession holds the schema definition for the GameSession entity.
type GameSession struct {
ent.Schema
}
// Fields of the GameSession.
func (GameSession) Fields() []ent.Field {
return []ent.Field{
field.String("id").
Unique().
Immutable(),
field.String("player_name").
NotEmpty().
Comment("Name of the player"),
field.String("user_id").
Optional().
Comment("Optional authenticated user ID"),
field.Int("total_score").
Default(0).
NonNegative().
Comment("Total score accumulated in this session"),
field.Int("questions_asked").
Default(0).
NonNegative().
Comment("Number of questions asked in this session"),
field.Int("questions_correct").
Default(0).
NonNegative().
Comment("Number of questions answered correctly"),
field.Int("hints_used").
Default(0).
NonNegative().
Comment("Number of hints used in this session"),
field.Time("start_time").
Default(time.Now).
Immutable().
Comment("When the game session started"),
field.Time("end_time").
Optional().
Nillable().
Comment("When the game session ended"),
field.Enum("status").
Values("active", "completed", "timeout", "abandoned").
Default("active").
Comment("Current status of the game session"),
field.String("current_question_id").
Optional().
Comment("ID of the current question being asked"),
field.Int("current_attempts").
Default(0).
NonNegative().
Comment("Number of attempts on current question"),
field.JSON("session_data", map[string]interface{}{}).
Optional().
Comment("Additional session data as JSON"),
}
}
// Edges of the GameSession.
func (GameSession) Edges() []ent.Edge {
return []ent.Edge{
edge.To("attempts", QuestionAttempt.Type),
edge.To("current_question", Question.Type).
Unique().
Field("current_question_id"),
}
}
// Indexes of the GameSession.
func (GameSession) Indexes() []ent.Index {
return []ent.Index{
index.Fields("user_id"),
index.Fields("status"),
index.Fields("start_time"),
index.Fields("end_time"),
index.Fields("status", "start_time"),
index.Fields("total_score"),
}
}