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

func (Contact) Fields() []ent.Field {
	return []ent.Field{
		field.String("wx_wxid").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("属主微信id"),
		field.Int("type").Optional().Default(1).
			Annotations(entsql.WithComments(true)).
			Comment("联系人类型：1好友，2群组，3公众号，4企业微信联系人"),
		field.String("wxid").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信id 公众号微信ID"),
		field.String("account").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信账号"),
		field.String("nickname").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("微信昵称 群备注名称"),
		field.String("markname").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("备注名"),
		field.String("headimg").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("头像"),
		field.Int("sex").Default(0).
			Annotations(entsql.WithComments(true)).
			Comment("性别 0未知 1男 2女"),
		field.String("starrole").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("星标 65/67=星标 1/3=未星标"),
		field.Int("dontseeit").Default(0).
			Annotations(entsql.WithComments(true)).
			Comment("不让他看我的朋友圈 0可以看 1不让看"),
		field.Int("dontseeme").Default(0).
			Annotations(entsql.WithComments(true)).
			Comment("不看他的朋友圈 0可以看 1不看 1=开启了不看他 128/129=仅聊天"),
		field.String("lag").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("所属标签id清单，多开会用逗号隔开"),
		field.String("gid").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("群组id"),
		field.String("gname").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("群组名称"),
		field.String("v3").Default("").
			Annotations(entsql.WithComments(true)).
			Comment("v3数据"),
		field.Uint64("organization_id").Optional().Default(1).
			Comment("机构 ID").
			Annotations(entsql.WithComments(true)),
	}
}

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

func (Contact) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("wx_wxid", "wxid").Unique(),
		index.Fields("wxid"),
		index.Fields("type"),
		index.Fields("gid"),
	}
}

func (Contact) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("contact_relationships", LabelRelationship.Type),
		edge.To("contact_messages", MessageRecords.Type),
	}
}

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