package schema

import (
	"entgo.io/ent/schema/index"
	"wechat-api/ent/schema/localmixin"

	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/field"
	"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
)

type CreditUsage struct {
	ent.Schema
}

func (CreditUsage) Fields() []ent.Field {
	return []ent.Field{
		field.String("user_id").Optional().MaxLen(255).Comment("user_id | 用户ID"),
		field.Float32("number").Comment("number | 积分改变量"),
		field.Int("status").Optional().Range(1, 2).Default(1).Comment("status | 状态 1-正常 2-禁用"),
		field.Int("ntype").Default(1).Comment("ntype | 积分变化类型：1-消耗 2-增加"),
		field.String("table").Default("").Comment("table | 积分变化表名"),
		field.Uint64("organization_id").Optional().Comment("organization_id | 租户ID"),
		field.Uint64("nid").Default(0).Comment("nid | 积分变化关联信息ID"),
		field.String("reason").Default("").MaxLen(255).Comment("reason | 积分变动原因"),
		field.String("operator").Default("").MaxLen(255).Comment("operator | 积分变动人"),
	}
}

func (CreditUsage) Mixin() []ent.Mixin {
	return []ent.Mixin{
		mixins.IDMixin{},
		localmixin.SoftDeleteMixin{},
	}
}

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

func (CreditUsage) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("organization_id"),
	}
}

func (CreditUsage) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.WithComments(true),
		entsql.Annotation{Table: "credit_usage"},
	}
}
