package schema

import (
	"entgo.io/ent/schema/edge"
	"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 Agent struct {
	ent.Schema
}

func (Agent) Fields() []ent.Field {
	return []ent.Field{
		field.String("name").MaxLen(255).Comment("name | 角色名称"),
		field.String("role").Comment("role | 角色设定"),
		field.Int("status").Optional().Range(1, 2).Default(1).Comment("status | 状态 1-正常 2-禁用"),
		field.String("background").Optional().Default("").Comment("background | 背景介绍"),
		field.String("examples").Optional().Default("").Comment("examples | 对话案例"),
		field.Uint64("organization_id").Positive().Comment("organization_id | 租户ID"),
		field.String("dataset_id").Default("").MaxLen(255).Comment("dataset_id | 知识库ID"),
		field.String("collection_id").Default("").MaxLen(255).Comment("collection_id | 集合ID"),
	}
}

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

func (Agent) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("wx_agent", Wx.Type),
		edge.To("token_agent", Token.Type),
		edge.To("wa_agent", Whatsapp.Type),
		edge.To("key_agent", ApiKey.Type),
	}
}

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

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