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

func (ContactField) Fields() []ent.Field {
	return []ent.Field{
		field.Uint64("contact_id").Default(1).
			Comment("联系人 ID").
			Annotations(entsql.WithComments(true)),
		field.String("form_id").
			Annotations(entsql.WithComments(true)).
			Comment("表单 id"),
		field.JSON("value", []string{}).
			Annotations(entsql.WithComments(true)).
			Comment("表单值"),
	}
}

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

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

func (ContactField) Edges() []ent.Edge {
	return []ent.Edge{
		edge.From("field_contact", Contact.Type).
			Ref("contact_fields").
			Unique().
			Field("contact_id").
			Required(),
	}
}

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