package schema

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

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

type Token struct {
	ent.Schema
}

func (Token) Fields() []ent.Field {
	return []ent.Field{
		field.Time("expire_at").Optional().Default(nil).Comment("过期时间"),
		field.String("token").Optional().Default("").Comment("Token"),
		field.String("mac").Optional().Default("").Comment("Mac地址"),
		field.Uint64("organization_id").Default(0).Comment("租户ID"),
		field.Uint64("agent_id").Default(0).Comment("智能体ID"),
		field.String("custom_agent_base").Optional().Default("").Comment("定制agent服务地址"),
		field.String("custom_agent_key").Optional().Default("").Comment("定制agent服务密钥"),
		field.String("openai_base").Optional().Default("").Comment("大模型服务地址"),
		field.String("openai_key").Optional().Default("").Comment("大模型服务密钥"),
	}
}

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

func (Token) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("token").Unique(),
	}
}

func (Token) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("agent", Agent.Type).
			Ref("token_agent").
			Unique().
			Field("agent_id").
			Required(),
	}
}

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