package schema

import (
	"wechat-api/ent/schema/localmixin"

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

type Wx struct {
	ent.Schema
}

func (Wx) Fields() []ent.Field {
	return []ent.Field{
		field.Uint64("server_id").Optional().Default(0).
			Annotations(entsql.WithComments(true)).
			Comment("服务器id"),
		field.String("port").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("端口号"),
		field.String("process_id").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("进程号"),
		field.String("callback").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("回调地址"),
		field.String("wxid").Default("").
			Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信id"),
		field.String("account").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信账号"),
		field.String("nickname").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信昵称"),
		field.String("tel").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("手机号"),
		field.String("head_big").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信头像"),
	}
}

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

func (Wx) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("server_id", "port").Unique(),
		index.Fields("wxid").Unique(),
		index.Fields("account"),
		index.Fields("nickname"),
		index.Fields("tel"),
	}
}

func (Wx) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("server", Server.Type).Ref("wxs").Unique().Field("server_id"),
	}
}

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