package schema

import (
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect"
	"entgo.io/ent/schema/field"
	"github.com/shopspring/decimal"
)

var defalutBalance = decimal.RequireFromString("0.00")

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

// Fields of the Wallet.
func (Wallet) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id").StorageKey("user_id").Immutable().Unique(),
		field.Other("balance", decimal.Decimal{}).
			Default(defalutBalance).
			SchemaType(map[string]string{
				dialect.Postgres: "decimal(12,2)",
			}),
		field.Other("frozen_balance", decimal.Decimal{}).
			Default(defalutBalance).
			SchemaType(map[string]string{
				dialect.Postgres: "decimal(12,2)",
			}),
		field.Int("version").Default(1),
		field.Time("updated_at").Default(time.Now),
	}
}

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