package schema

import (
	"time"

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

type Reviews struct {
	ent.Schema
}

func (Reviews) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id").Unique().Immutable(),
		field.Int64("order_id"),
		field.Int64("from_user_id"),
		field.String("from_user_name").MaxLen(100),
		field.String("from_user_avatar").Optional().Default(""),
		field.Int64("to_user_id"),
		field.Int16("rating"),
		field.String("content").Optional().Default(""),
		field.Bool("sealed").Default(true),
		field.Time("created_at").Default(time.Now).Immutable(),
		field.Time("unsealed_at").Optional().Nillable(),
	}
}

func (Reviews) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("order_id", "from_user_id").Unique(),
		index.Fields("order_id"),
		index.Fields("to_user_id", "created_at"),
		index.Fields("from_user_id"),
	}
}

func (Reviews) Edges() []ent.Edge {
	return nil
}
