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 XunjiService struct {
	ent.Schema
}

func (XunjiService) Fields() []ent.Field {
	return []ent.Field{
		field.Uint64("xunji_id").Comment("Xunji表ID"),
		field.Uint64("agent_id").Default(0).Comment("智能体ID"),
		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
		field.String("wxid").Comment("微信ID"),
		field.String("api_base").Optional().Default("").Comment("大模型服务地址"),
		field.String("api_key").Optional().Default("").Comment("大模型服务密钥"),
	}
}

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

func (XunjiService) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("xunji_id"),
		index.Fields("wxid"),
	}
}

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

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