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"
	"github.com/suyuan32/simple-admin-common/orm/ent/mixins"
)

type Whatsapp struct {
	ent.Schema
}

func (Whatsapp) Fields() []ent.Field {
	return []ent.Field{
		field.String("wa_id").Optional().Default("").Comment("通道ID"),
		field.String("wa_name").Optional().Default("").Comment("通道名"),
		field.String("callback").Optional().Default("").Comment("回调地址"),
		field.Uint64("agent_id").Default(0).Comment("AI角色ID"),
		field.String("account").Optional().Default("").Comment("账号"),
		field.String("cc").Default("").Comment("国家区号"),
		field.String("phone").Default("").Comment("手机号"),
		field.String("cc_phone").Default("").Comment("国家区号 + 手机号"),
		field.String("phone_name").Default("").Comment("号码名称"),
		field.Int8("phone_status").Default(0).Comment("号码状态"),
		field.Uint64("organization_id").Optional().Default(0).Comment("机构 ID"),
		field.String("api_base").Optional().Default("").Comment("大模型服务账号"),
		field.String("api_key").Optional().Default("").Comment("大模型服务密钥"),
		field.JSON("allow_list", []string{}).Optional().Comment("白名单"),
		field.JSON("group_allow_list", []string{}).Optional().Comment("群白名单"),
		field.JSON("block_list", []string{}).Optional().Comment("黑名单"),
		field.JSON("group_block_list", []string{}).Optional().Comment("群黑名单"),
	}
}

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

func (Whatsapp) Indexes() []ent.Index {
	return []ent.Index{}
}

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

func (Whatsapp) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{Table: "whatsapp"},
	}
}
