// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/contact"
	"wechat-api/ent/labelrelationship"
	"wechat-api/ent/messagerecords"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// ContactCreate is the builder for creating a Contact entity.
type ContactCreate struct {
	config
	mutation *ContactMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreatedAt sets the "created_at" field.
func (cc *ContactCreate) SetCreatedAt(t time.Time) *ContactCreate {
	cc.mutation.SetCreatedAt(t)
	return cc
}

// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (cc *ContactCreate) SetNillableCreatedAt(t *time.Time) *ContactCreate {
	if t != nil {
		cc.SetCreatedAt(*t)
	}
	return cc
}

// SetUpdatedAt sets the "updated_at" field.
func (cc *ContactCreate) SetUpdatedAt(t time.Time) *ContactCreate {
	cc.mutation.SetUpdatedAt(t)
	return cc
}

// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (cc *ContactCreate) SetNillableUpdatedAt(t *time.Time) *ContactCreate {
	if t != nil {
		cc.SetUpdatedAt(*t)
	}
	return cc
}

// SetStatus sets the "status" field.
func (cc *ContactCreate) SetStatus(u uint8) *ContactCreate {
	cc.mutation.SetStatus(u)
	return cc
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (cc *ContactCreate) SetNillableStatus(u *uint8) *ContactCreate {
	if u != nil {
		cc.SetStatus(*u)
	}
	return cc
}

// SetDeletedAt sets the "deleted_at" field.
func (cc *ContactCreate) SetDeletedAt(t time.Time) *ContactCreate {
	cc.mutation.SetDeletedAt(t)
	return cc
}

// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
func (cc *ContactCreate) SetNillableDeletedAt(t *time.Time) *ContactCreate {
	if t != nil {
		cc.SetDeletedAt(*t)
	}
	return cc
}

// SetWxWxid sets the "wx_wxid" field.
func (cc *ContactCreate) SetWxWxid(s string) *ContactCreate {
	cc.mutation.SetWxWxid(s)
	return cc
}

// SetNillableWxWxid sets the "wx_wxid" field if the given value is not nil.
func (cc *ContactCreate) SetNillableWxWxid(s *string) *ContactCreate {
	if s != nil {
		cc.SetWxWxid(*s)
	}
	return cc
}

// SetType sets the "type" field.
func (cc *ContactCreate) SetType(i int) *ContactCreate {
	cc.mutation.SetType(i)
	return cc
}

// SetNillableType sets the "type" field if the given value is not nil.
func (cc *ContactCreate) SetNillableType(i *int) *ContactCreate {
	if i != nil {
		cc.SetType(*i)
	}
	return cc
}

// SetWxid sets the "wxid" field.
func (cc *ContactCreate) SetWxid(s string) *ContactCreate {
	cc.mutation.SetWxid(s)
	return cc
}

// SetNillableWxid sets the "wxid" field if the given value is not nil.
func (cc *ContactCreate) SetNillableWxid(s *string) *ContactCreate {
	if s != nil {
		cc.SetWxid(*s)
	}
	return cc
}

// SetAccount sets the "account" field.
func (cc *ContactCreate) SetAccount(s string) *ContactCreate {
	cc.mutation.SetAccount(s)
	return cc
}

// SetNillableAccount sets the "account" field if the given value is not nil.
func (cc *ContactCreate) SetNillableAccount(s *string) *ContactCreate {
	if s != nil {
		cc.SetAccount(*s)
	}
	return cc
}

// SetNickname sets the "nickname" field.
func (cc *ContactCreate) SetNickname(s string) *ContactCreate {
	cc.mutation.SetNickname(s)
	return cc
}

// SetNillableNickname sets the "nickname" field if the given value is not nil.
func (cc *ContactCreate) SetNillableNickname(s *string) *ContactCreate {
	if s != nil {
		cc.SetNickname(*s)
	}
	return cc
}

// SetMarkname sets the "markname" field.
func (cc *ContactCreate) SetMarkname(s string) *ContactCreate {
	cc.mutation.SetMarkname(s)
	return cc
}

// SetNillableMarkname sets the "markname" field if the given value is not nil.
func (cc *ContactCreate) SetNillableMarkname(s *string) *ContactCreate {
	if s != nil {
		cc.SetMarkname(*s)
	}
	return cc
}

// SetHeadimg sets the "headimg" field.
func (cc *ContactCreate) SetHeadimg(s string) *ContactCreate {
	cc.mutation.SetHeadimg(s)
	return cc
}

// SetNillableHeadimg sets the "headimg" field if the given value is not nil.
func (cc *ContactCreate) SetNillableHeadimg(s *string) *ContactCreate {
	if s != nil {
		cc.SetHeadimg(*s)
	}
	return cc
}

// SetSex sets the "sex" field.
func (cc *ContactCreate) SetSex(i int) *ContactCreate {
	cc.mutation.SetSex(i)
	return cc
}

// SetNillableSex sets the "sex" field if the given value is not nil.
func (cc *ContactCreate) SetNillableSex(i *int) *ContactCreate {
	if i != nil {
		cc.SetSex(*i)
	}
	return cc
}

// SetStarrole sets the "starrole" field.
func (cc *ContactCreate) SetStarrole(s string) *ContactCreate {
	cc.mutation.SetStarrole(s)
	return cc
}

// SetNillableStarrole sets the "starrole" field if the given value is not nil.
func (cc *ContactCreate) SetNillableStarrole(s *string) *ContactCreate {
	if s != nil {
		cc.SetStarrole(*s)
	}
	return cc
}

// SetDontseeit sets the "dontseeit" field.
func (cc *ContactCreate) SetDontseeit(i int) *ContactCreate {
	cc.mutation.SetDontseeit(i)
	return cc
}

// SetNillableDontseeit sets the "dontseeit" field if the given value is not nil.
func (cc *ContactCreate) SetNillableDontseeit(i *int) *ContactCreate {
	if i != nil {
		cc.SetDontseeit(*i)
	}
	return cc
}

// SetDontseeme sets the "dontseeme" field.
func (cc *ContactCreate) SetDontseeme(i int) *ContactCreate {
	cc.mutation.SetDontseeme(i)
	return cc
}

// SetNillableDontseeme sets the "dontseeme" field if the given value is not nil.
func (cc *ContactCreate) SetNillableDontseeme(i *int) *ContactCreate {
	if i != nil {
		cc.SetDontseeme(*i)
	}
	return cc
}

// SetLag sets the "lag" field.
func (cc *ContactCreate) SetLag(s string) *ContactCreate {
	cc.mutation.SetLag(s)
	return cc
}

// SetNillableLag sets the "lag" field if the given value is not nil.
func (cc *ContactCreate) SetNillableLag(s *string) *ContactCreate {
	if s != nil {
		cc.SetLag(*s)
	}
	return cc
}

// SetGid sets the "gid" field.
func (cc *ContactCreate) SetGid(s string) *ContactCreate {
	cc.mutation.SetGid(s)
	return cc
}

// SetNillableGid sets the "gid" field if the given value is not nil.
func (cc *ContactCreate) SetNillableGid(s *string) *ContactCreate {
	if s != nil {
		cc.SetGid(*s)
	}
	return cc
}

// SetGname sets the "gname" field.
func (cc *ContactCreate) SetGname(s string) *ContactCreate {
	cc.mutation.SetGname(s)
	return cc
}

// SetNillableGname sets the "gname" field if the given value is not nil.
func (cc *ContactCreate) SetNillableGname(s *string) *ContactCreate {
	if s != nil {
		cc.SetGname(*s)
	}
	return cc
}

// SetV3 sets the "v3" field.
func (cc *ContactCreate) SetV3(s string) *ContactCreate {
	cc.mutation.SetV3(s)
	return cc
}

// SetNillableV3 sets the "v3" field if the given value is not nil.
func (cc *ContactCreate) SetNillableV3(s *string) *ContactCreate {
	if s != nil {
		cc.SetV3(*s)
	}
	return cc
}

// SetOrganizationID sets the "organization_id" field.
func (cc *ContactCreate) SetOrganizationID(u uint64) *ContactCreate {
	cc.mutation.SetOrganizationID(u)
	return cc
}

// SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
func (cc *ContactCreate) SetNillableOrganizationID(u *uint64) *ContactCreate {
	if u != nil {
		cc.SetOrganizationID(*u)
	}
	return cc
}

// SetID sets the "id" field.
func (cc *ContactCreate) SetID(u uint64) *ContactCreate {
	cc.mutation.SetID(u)
	return cc
}

// AddContactRelationshipIDs adds the "contact_relationships" edge to the LabelRelationship entity by IDs.
func (cc *ContactCreate) AddContactRelationshipIDs(ids ...uint64) *ContactCreate {
	cc.mutation.AddContactRelationshipIDs(ids...)
	return cc
}

// AddContactRelationships adds the "contact_relationships" edges to the LabelRelationship entity.
func (cc *ContactCreate) AddContactRelationships(l ...*LabelRelationship) *ContactCreate {
	ids := make([]uint64, len(l))
	for i := range l {
		ids[i] = l[i].ID
	}
	return cc.AddContactRelationshipIDs(ids...)
}

// AddContactMessageIDs adds the "contact_messages" edge to the MessageRecords entity by IDs.
func (cc *ContactCreate) AddContactMessageIDs(ids ...uint64) *ContactCreate {
	cc.mutation.AddContactMessageIDs(ids...)
	return cc
}

// AddContactMessages adds the "contact_messages" edges to the MessageRecords entity.
func (cc *ContactCreate) AddContactMessages(m ...*MessageRecords) *ContactCreate {
	ids := make([]uint64, len(m))
	for i := range m {
		ids[i] = m[i].ID
	}
	return cc.AddContactMessageIDs(ids...)
}

// Mutation returns the ContactMutation object of the builder.
func (cc *ContactCreate) Mutation() *ContactMutation {
	return cc.mutation
}

// Save creates the Contact in the database.
func (cc *ContactCreate) Save(ctx context.Context) (*Contact, error) {
	if err := cc.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
}

// SaveX calls Save and panics if Save returns an error.
func (cc *ContactCreate) SaveX(ctx context.Context) *Contact {
	v, err := cc.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (cc *ContactCreate) Exec(ctx context.Context) error {
	_, err := cc.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (cc *ContactCreate) ExecX(ctx context.Context) {
	if err := cc.Exec(ctx); err != nil {
		panic(err)
	}
}

// defaults sets the default values of the builder before save.
func (cc *ContactCreate) defaults() error {
	if _, ok := cc.mutation.CreatedAt(); !ok {
		if contact.DefaultCreatedAt == nil {
			return fmt.Errorf("ent: uninitialized contact.DefaultCreatedAt (forgotten import ent/runtime?)")
		}
		v := contact.DefaultCreatedAt()
		cc.mutation.SetCreatedAt(v)
	}
	if _, ok := cc.mutation.UpdatedAt(); !ok {
		if contact.DefaultUpdatedAt == nil {
			return fmt.Errorf("ent: uninitialized contact.DefaultUpdatedAt (forgotten import ent/runtime?)")
		}
		v := contact.DefaultUpdatedAt()
		cc.mutation.SetUpdatedAt(v)
	}
	if _, ok := cc.mutation.Status(); !ok {
		v := contact.DefaultStatus
		cc.mutation.SetStatus(v)
	}
	if _, ok := cc.mutation.WxWxid(); !ok {
		v := contact.DefaultWxWxid
		cc.mutation.SetWxWxid(v)
	}
	if _, ok := cc.mutation.GetType(); !ok {
		v := contact.DefaultType
		cc.mutation.SetType(v)
	}
	if _, ok := cc.mutation.Wxid(); !ok {
		v := contact.DefaultWxid
		cc.mutation.SetWxid(v)
	}
	if _, ok := cc.mutation.Account(); !ok {
		v := contact.DefaultAccount
		cc.mutation.SetAccount(v)
	}
	if _, ok := cc.mutation.Nickname(); !ok {
		v := contact.DefaultNickname
		cc.mutation.SetNickname(v)
	}
	if _, ok := cc.mutation.Markname(); !ok {
		v := contact.DefaultMarkname
		cc.mutation.SetMarkname(v)
	}
	if _, ok := cc.mutation.Headimg(); !ok {
		v := contact.DefaultHeadimg
		cc.mutation.SetHeadimg(v)
	}
	if _, ok := cc.mutation.Sex(); !ok {
		v := contact.DefaultSex
		cc.mutation.SetSex(v)
	}
	if _, ok := cc.mutation.Starrole(); !ok {
		v := contact.DefaultStarrole
		cc.mutation.SetStarrole(v)
	}
	if _, ok := cc.mutation.Dontseeit(); !ok {
		v := contact.DefaultDontseeit
		cc.mutation.SetDontseeit(v)
	}
	if _, ok := cc.mutation.Dontseeme(); !ok {
		v := contact.DefaultDontseeme
		cc.mutation.SetDontseeme(v)
	}
	if _, ok := cc.mutation.Lag(); !ok {
		v := contact.DefaultLag
		cc.mutation.SetLag(v)
	}
	if _, ok := cc.mutation.Gid(); !ok {
		v := contact.DefaultGid
		cc.mutation.SetGid(v)
	}
	if _, ok := cc.mutation.Gname(); !ok {
		v := contact.DefaultGname
		cc.mutation.SetGname(v)
	}
	if _, ok := cc.mutation.V3(); !ok {
		v := contact.DefaultV3
		cc.mutation.SetV3(v)
	}
	if _, ok := cc.mutation.OrganizationID(); !ok {
		v := contact.DefaultOrganizationID
		cc.mutation.SetOrganizationID(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (cc *ContactCreate) check() error {
	if _, ok := cc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Contact.created_at"`)}
	}
	if _, ok := cc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Contact.updated_at"`)}
	}
	if _, ok := cc.mutation.WxWxid(); !ok {
		return &ValidationError{Name: "wx_wxid", err: errors.New(`ent: missing required field "Contact.wx_wxid"`)}
	}
	if _, ok := cc.mutation.Wxid(); !ok {
		return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "Contact.wxid"`)}
	}
	if _, ok := cc.mutation.Account(); !ok {
		return &ValidationError{Name: "account", err: errors.New(`ent: missing required field "Contact.account"`)}
	}
	if _, ok := cc.mutation.Nickname(); !ok {
		return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "Contact.nickname"`)}
	}
	if _, ok := cc.mutation.Markname(); !ok {
		return &ValidationError{Name: "markname", err: errors.New(`ent: missing required field "Contact.markname"`)}
	}
	if _, ok := cc.mutation.Headimg(); !ok {
		return &ValidationError{Name: "headimg", err: errors.New(`ent: missing required field "Contact.headimg"`)}
	}
	if _, ok := cc.mutation.Sex(); !ok {
		return &ValidationError{Name: "sex", err: errors.New(`ent: missing required field "Contact.sex"`)}
	}
	if _, ok := cc.mutation.Starrole(); !ok {
		return &ValidationError{Name: "starrole", err: errors.New(`ent: missing required field "Contact.starrole"`)}
	}
	if _, ok := cc.mutation.Dontseeit(); !ok {
		return &ValidationError{Name: "dontseeit", err: errors.New(`ent: missing required field "Contact.dontseeit"`)}
	}
	if _, ok := cc.mutation.Dontseeme(); !ok {
		return &ValidationError{Name: "dontseeme", err: errors.New(`ent: missing required field "Contact.dontseeme"`)}
	}
	if _, ok := cc.mutation.Lag(); !ok {
		return &ValidationError{Name: "lag", err: errors.New(`ent: missing required field "Contact.lag"`)}
	}
	if _, ok := cc.mutation.Gid(); !ok {
		return &ValidationError{Name: "gid", err: errors.New(`ent: missing required field "Contact.gid"`)}
	}
	if _, ok := cc.mutation.Gname(); !ok {
		return &ValidationError{Name: "gname", err: errors.New(`ent: missing required field "Contact.gname"`)}
	}
	if _, ok := cc.mutation.V3(); !ok {
		return &ValidationError{Name: "v3", err: errors.New(`ent: missing required field "Contact.v3"`)}
	}
	return nil
}

func (cc *ContactCreate) sqlSave(ctx context.Context) (*Contact, error) {
	if err := cc.check(); err != nil {
		return nil, err
	}
	_node, _spec := cc.createSpec()
	if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != _node.ID {
		id := _spec.ID.Value.(int64)
		_node.ID = uint64(id)
	}
	cc.mutation.id = &_node.ID
	cc.mutation.done = true
	return _node, nil
}

func (cc *ContactCreate) createSpec() (*Contact, *sqlgraph.CreateSpec) {
	var (
		_node = &Contact{config: cc.config}
		_spec = sqlgraph.NewCreateSpec(contact.Table, sqlgraph.NewFieldSpec(contact.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = cc.conflict
	if id, ok := cc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := cc.mutation.CreatedAt(); ok {
		_spec.SetField(contact.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := cc.mutation.UpdatedAt(); ok {
		_spec.SetField(contact.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := cc.mutation.Status(); ok {
		_spec.SetField(contact.FieldStatus, field.TypeUint8, value)
		_node.Status = value
	}
	if value, ok := cc.mutation.DeletedAt(); ok {
		_spec.SetField(contact.FieldDeletedAt, field.TypeTime, value)
		_node.DeletedAt = value
	}
	if value, ok := cc.mutation.WxWxid(); ok {
		_spec.SetField(contact.FieldWxWxid, field.TypeString, value)
		_node.WxWxid = value
	}
	if value, ok := cc.mutation.GetType(); ok {
		_spec.SetField(contact.FieldType, field.TypeInt, value)
		_node.Type = value
	}
	if value, ok := cc.mutation.Wxid(); ok {
		_spec.SetField(contact.FieldWxid, field.TypeString, value)
		_node.Wxid = value
	}
	if value, ok := cc.mutation.Account(); ok {
		_spec.SetField(contact.FieldAccount, field.TypeString, value)
		_node.Account = value
	}
	if value, ok := cc.mutation.Nickname(); ok {
		_spec.SetField(contact.FieldNickname, field.TypeString, value)
		_node.Nickname = value
	}
	if value, ok := cc.mutation.Markname(); ok {
		_spec.SetField(contact.FieldMarkname, field.TypeString, value)
		_node.Markname = value
	}
	if value, ok := cc.mutation.Headimg(); ok {
		_spec.SetField(contact.FieldHeadimg, field.TypeString, value)
		_node.Headimg = value
	}
	if value, ok := cc.mutation.Sex(); ok {
		_spec.SetField(contact.FieldSex, field.TypeInt, value)
		_node.Sex = value
	}
	if value, ok := cc.mutation.Starrole(); ok {
		_spec.SetField(contact.FieldStarrole, field.TypeString, value)
		_node.Starrole = value
	}
	if value, ok := cc.mutation.Dontseeit(); ok {
		_spec.SetField(contact.FieldDontseeit, field.TypeInt, value)
		_node.Dontseeit = value
	}
	if value, ok := cc.mutation.Dontseeme(); ok {
		_spec.SetField(contact.FieldDontseeme, field.TypeInt, value)
		_node.Dontseeme = value
	}
	if value, ok := cc.mutation.Lag(); ok {
		_spec.SetField(contact.FieldLag, field.TypeString, value)
		_node.Lag = value
	}
	if value, ok := cc.mutation.Gid(); ok {
		_spec.SetField(contact.FieldGid, field.TypeString, value)
		_node.Gid = value
	}
	if value, ok := cc.mutation.Gname(); ok {
		_spec.SetField(contact.FieldGname, field.TypeString, value)
		_node.Gname = value
	}
	if value, ok := cc.mutation.V3(); ok {
		_spec.SetField(contact.FieldV3, field.TypeString, value)
		_node.V3 = value
	}
	if value, ok := cc.mutation.OrganizationID(); ok {
		_spec.SetField(contact.FieldOrganizationID, field.TypeUint64, value)
		_node.OrganizationID = value
	}
	if nodes := cc.mutation.ContactRelationshipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   contact.ContactRelationshipsTable,
			Columns: []string{contact.ContactRelationshipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(labelrelationship.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := cc.mutation.ContactMessagesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   contact.ContactMessagesTable,
			Columns: []string{contact.ContactMessagesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(messagerecords.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Contact.Create().
//		SetCreatedAt(v).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.ContactUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (cc *ContactCreate) OnConflict(opts ...sql.ConflictOption) *ContactUpsertOne {
	cc.conflict = opts
	return &ContactUpsertOne{
		create: cc,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Contact.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (cc *ContactCreate) OnConflictColumns(columns ...string) *ContactUpsertOne {
	cc.conflict = append(cc.conflict, sql.ConflictColumns(columns...))
	return &ContactUpsertOne{
		create: cc,
	}
}

type (
	// ContactUpsertOne is the builder for "upsert"-ing
	//  one Contact node.
	ContactUpsertOne struct {
		create *ContactCreate
	}

	// ContactUpsert is the "OnConflict" setter.
	ContactUpsert struct {
		*sql.UpdateSet
	}
)

// SetUpdatedAt sets the "updated_at" field.
func (u *ContactUpsert) SetUpdatedAt(v time.Time) *ContactUpsert {
	u.Set(contact.FieldUpdatedAt, v)
	return u
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *ContactUpsert) UpdateUpdatedAt() *ContactUpsert {
	u.SetExcluded(contact.FieldUpdatedAt)
	return u
}

// SetStatus sets the "status" field.
func (u *ContactUpsert) SetStatus(v uint8) *ContactUpsert {
	u.Set(contact.FieldStatus, v)
	return u
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *ContactUpsert) UpdateStatus() *ContactUpsert {
	u.SetExcluded(contact.FieldStatus)
	return u
}

// AddStatus adds v to the "status" field.
func (u *ContactUpsert) AddStatus(v uint8) *ContactUpsert {
	u.Add(contact.FieldStatus, v)
	return u
}

// ClearStatus clears the value of the "status" field.
func (u *ContactUpsert) ClearStatus() *ContactUpsert {
	u.SetNull(contact.FieldStatus)
	return u
}

// SetDeletedAt sets the "deleted_at" field.
func (u *ContactUpsert) SetDeletedAt(v time.Time) *ContactUpsert {
	u.Set(contact.FieldDeletedAt, v)
	return u
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *ContactUpsert) UpdateDeletedAt() *ContactUpsert {
	u.SetExcluded(contact.FieldDeletedAt)
	return u
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *ContactUpsert) ClearDeletedAt() *ContactUpsert {
	u.SetNull(contact.FieldDeletedAt)
	return u
}

// SetWxWxid sets the "wx_wxid" field.
func (u *ContactUpsert) SetWxWxid(v string) *ContactUpsert {
	u.Set(contact.FieldWxWxid, v)
	return u
}

// UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create.
func (u *ContactUpsert) UpdateWxWxid() *ContactUpsert {
	u.SetExcluded(contact.FieldWxWxid)
	return u
}

// SetType sets the "type" field.
func (u *ContactUpsert) SetType(v int) *ContactUpsert {
	u.Set(contact.FieldType, v)
	return u
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *ContactUpsert) UpdateType() *ContactUpsert {
	u.SetExcluded(contact.FieldType)
	return u
}

// AddType adds v to the "type" field.
func (u *ContactUpsert) AddType(v int) *ContactUpsert {
	u.Add(contact.FieldType, v)
	return u
}

// ClearType clears the value of the "type" field.
func (u *ContactUpsert) ClearType() *ContactUpsert {
	u.SetNull(contact.FieldType)
	return u
}

// SetWxid sets the "wxid" field.
func (u *ContactUpsert) SetWxid(v string) *ContactUpsert {
	u.Set(contact.FieldWxid, v)
	return u
}

// UpdateWxid sets the "wxid" field to the value that was provided on create.
func (u *ContactUpsert) UpdateWxid() *ContactUpsert {
	u.SetExcluded(contact.FieldWxid)
	return u
}

// SetAccount sets the "account" field.
func (u *ContactUpsert) SetAccount(v string) *ContactUpsert {
	u.Set(contact.FieldAccount, v)
	return u
}

// UpdateAccount sets the "account" field to the value that was provided on create.
func (u *ContactUpsert) UpdateAccount() *ContactUpsert {
	u.SetExcluded(contact.FieldAccount)
	return u
}

// SetNickname sets the "nickname" field.
func (u *ContactUpsert) SetNickname(v string) *ContactUpsert {
	u.Set(contact.FieldNickname, v)
	return u
}

// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *ContactUpsert) UpdateNickname() *ContactUpsert {
	u.SetExcluded(contact.FieldNickname)
	return u
}

// SetMarkname sets the "markname" field.
func (u *ContactUpsert) SetMarkname(v string) *ContactUpsert {
	u.Set(contact.FieldMarkname, v)
	return u
}

// UpdateMarkname sets the "markname" field to the value that was provided on create.
func (u *ContactUpsert) UpdateMarkname() *ContactUpsert {
	u.SetExcluded(contact.FieldMarkname)
	return u
}

// SetHeadimg sets the "headimg" field.
func (u *ContactUpsert) SetHeadimg(v string) *ContactUpsert {
	u.Set(contact.FieldHeadimg, v)
	return u
}

// UpdateHeadimg sets the "headimg" field to the value that was provided on create.
func (u *ContactUpsert) UpdateHeadimg() *ContactUpsert {
	u.SetExcluded(contact.FieldHeadimg)
	return u
}

// SetSex sets the "sex" field.
func (u *ContactUpsert) SetSex(v int) *ContactUpsert {
	u.Set(contact.FieldSex, v)
	return u
}

// UpdateSex sets the "sex" field to the value that was provided on create.
func (u *ContactUpsert) UpdateSex() *ContactUpsert {
	u.SetExcluded(contact.FieldSex)
	return u
}

// AddSex adds v to the "sex" field.
func (u *ContactUpsert) AddSex(v int) *ContactUpsert {
	u.Add(contact.FieldSex, v)
	return u
}

// SetStarrole sets the "starrole" field.
func (u *ContactUpsert) SetStarrole(v string) *ContactUpsert {
	u.Set(contact.FieldStarrole, v)
	return u
}

// UpdateStarrole sets the "starrole" field to the value that was provided on create.
func (u *ContactUpsert) UpdateStarrole() *ContactUpsert {
	u.SetExcluded(contact.FieldStarrole)
	return u
}

// SetDontseeit sets the "dontseeit" field.
func (u *ContactUpsert) SetDontseeit(v int) *ContactUpsert {
	u.Set(contact.FieldDontseeit, v)
	return u
}

// UpdateDontseeit sets the "dontseeit" field to the value that was provided on create.
func (u *ContactUpsert) UpdateDontseeit() *ContactUpsert {
	u.SetExcluded(contact.FieldDontseeit)
	return u
}

// AddDontseeit adds v to the "dontseeit" field.
func (u *ContactUpsert) AddDontseeit(v int) *ContactUpsert {
	u.Add(contact.FieldDontseeit, v)
	return u
}

// SetDontseeme sets the "dontseeme" field.
func (u *ContactUpsert) SetDontseeme(v int) *ContactUpsert {
	u.Set(contact.FieldDontseeme, v)
	return u
}

// UpdateDontseeme sets the "dontseeme" field to the value that was provided on create.
func (u *ContactUpsert) UpdateDontseeme() *ContactUpsert {
	u.SetExcluded(contact.FieldDontseeme)
	return u
}

// AddDontseeme adds v to the "dontseeme" field.
func (u *ContactUpsert) AddDontseeme(v int) *ContactUpsert {
	u.Add(contact.FieldDontseeme, v)
	return u
}

// SetLag sets the "lag" field.
func (u *ContactUpsert) SetLag(v string) *ContactUpsert {
	u.Set(contact.FieldLag, v)
	return u
}

// UpdateLag sets the "lag" field to the value that was provided on create.
func (u *ContactUpsert) UpdateLag() *ContactUpsert {
	u.SetExcluded(contact.FieldLag)
	return u
}

// SetGid sets the "gid" field.
func (u *ContactUpsert) SetGid(v string) *ContactUpsert {
	u.Set(contact.FieldGid, v)
	return u
}

// UpdateGid sets the "gid" field to the value that was provided on create.
func (u *ContactUpsert) UpdateGid() *ContactUpsert {
	u.SetExcluded(contact.FieldGid)
	return u
}

// SetGname sets the "gname" field.
func (u *ContactUpsert) SetGname(v string) *ContactUpsert {
	u.Set(contact.FieldGname, v)
	return u
}

// UpdateGname sets the "gname" field to the value that was provided on create.
func (u *ContactUpsert) UpdateGname() *ContactUpsert {
	u.SetExcluded(contact.FieldGname)
	return u
}

// SetV3 sets the "v3" field.
func (u *ContactUpsert) SetV3(v string) *ContactUpsert {
	u.Set(contact.FieldV3, v)
	return u
}

// UpdateV3 sets the "v3" field to the value that was provided on create.
func (u *ContactUpsert) UpdateV3() *ContactUpsert {
	u.SetExcluded(contact.FieldV3)
	return u
}

// SetOrganizationID sets the "organization_id" field.
func (u *ContactUpsert) SetOrganizationID(v uint64) *ContactUpsert {
	u.Set(contact.FieldOrganizationID, v)
	return u
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *ContactUpsert) UpdateOrganizationID() *ContactUpsert {
	u.SetExcluded(contact.FieldOrganizationID)
	return u
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *ContactUpsert) AddOrganizationID(v uint64) *ContactUpsert {
	u.Add(contact.FieldOrganizationID, v)
	return u
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *ContactUpsert) ClearOrganizationID() *ContactUpsert {
	u.SetNull(contact.FieldOrganizationID)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
// Using this option is equivalent to using:
//
//	client.Contact.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(contact.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *ContactUpsertOne) UpdateNewValues() *ContactUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		if _, exists := u.create.mutation.ID(); exists {
			s.SetIgnore(contact.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(contact.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Contact.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *ContactUpsertOne) Ignore() *ContactUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *ContactUpsertOne) DoNothing() *ContactUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the ContactCreate.OnConflict
// documentation for more info.
func (u *ContactUpsertOne) Update(set func(*ContactUpsert)) *ContactUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&ContactUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *ContactUpsertOne) SetUpdatedAt(v time.Time) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateUpdatedAt() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetStatus sets the "status" field.
func (u *ContactUpsertOne) SetStatus(v uint8) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *ContactUpsertOne) AddStatus(v uint8) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.AddStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateStatus() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateStatus()
	})
}

// ClearStatus clears the value of the "status" field.
func (u *ContactUpsertOne) ClearStatus() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.ClearStatus()
	})
}

// SetDeletedAt sets the "deleted_at" field.
func (u *ContactUpsertOne) SetDeletedAt(v time.Time) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateDeletedAt() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *ContactUpsertOne) ClearDeletedAt() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.ClearDeletedAt()
	})
}

// SetWxWxid sets the "wx_wxid" field.
func (u *ContactUpsertOne) SetWxWxid(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetWxWxid(v)
	})
}

// UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateWxWxid() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateWxWxid()
	})
}

// SetType sets the "type" field.
func (u *ContactUpsertOne) SetType(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetType(v)
	})
}

// AddType adds v to the "type" field.
func (u *ContactUpsertOne) AddType(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.AddType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateType() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateType()
	})
}

// ClearType clears the value of the "type" field.
func (u *ContactUpsertOne) ClearType() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.ClearType()
	})
}

// SetWxid sets the "wxid" field.
func (u *ContactUpsertOne) SetWxid(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetWxid(v)
	})
}

// UpdateWxid sets the "wxid" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateWxid() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateWxid()
	})
}

// SetAccount sets the "account" field.
func (u *ContactUpsertOne) SetAccount(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetAccount(v)
	})
}

// UpdateAccount sets the "account" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateAccount() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateAccount()
	})
}

// SetNickname sets the "nickname" field.
func (u *ContactUpsertOne) SetNickname(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetNickname(v)
	})
}

// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateNickname() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateNickname()
	})
}

// SetMarkname sets the "markname" field.
func (u *ContactUpsertOne) SetMarkname(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetMarkname(v)
	})
}

// UpdateMarkname sets the "markname" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateMarkname() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateMarkname()
	})
}

// SetHeadimg sets the "headimg" field.
func (u *ContactUpsertOne) SetHeadimg(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetHeadimg(v)
	})
}

// UpdateHeadimg sets the "headimg" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateHeadimg() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateHeadimg()
	})
}

// SetSex sets the "sex" field.
func (u *ContactUpsertOne) SetSex(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetSex(v)
	})
}

// AddSex adds v to the "sex" field.
func (u *ContactUpsertOne) AddSex(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.AddSex(v)
	})
}

// UpdateSex sets the "sex" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateSex() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateSex()
	})
}

// SetStarrole sets the "starrole" field.
func (u *ContactUpsertOne) SetStarrole(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetStarrole(v)
	})
}

// UpdateStarrole sets the "starrole" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateStarrole() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateStarrole()
	})
}

// SetDontseeit sets the "dontseeit" field.
func (u *ContactUpsertOne) SetDontseeit(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetDontseeit(v)
	})
}

// AddDontseeit adds v to the "dontseeit" field.
func (u *ContactUpsertOne) AddDontseeit(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.AddDontseeit(v)
	})
}

// UpdateDontseeit sets the "dontseeit" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateDontseeit() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateDontseeit()
	})
}

// SetDontseeme sets the "dontseeme" field.
func (u *ContactUpsertOne) SetDontseeme(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetDontseeme(v)
	})
}

// AddDontseeme adds v to the "dontseeme" field.
func (u *ContactUpsertOne) AddDontseeme(v int) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.AddDontseeme(v)
	})
}

// UpdateDontseeme sets the "dontseeme" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateDontseeme() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateDontseeme()
	})
}

// SetLag sets the "lag" field.
func (u *ContactUpsertOne) SetLag(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetLag(v)
	})
}

// UpdateLag sets the "lag" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateLag() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateLag()
	})
}

// SetGid sets the "gid" field.
func (u *ContactUpsertOne) SetGid(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetGid(v)
	})
}

// UpdateGid sets the "gid" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateGid() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateGid()
	})
}

// SetGname sets the "gname" field.
func (u *ContactUpsertOne) SetGname(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetGname(v)
	})
}

// UpdateGname sets the "gname" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateGname() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateGname()
	})
}

// SetV3 sets the "v3" field.
func (u *ContactUpsertOne) SetV3(v string) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetV3(v)
	})
}

// UpdateV3 sets the "v3" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateV3() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateV3()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *ContactUpsertOne) SetOrganizationID(v uint64) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *ContactUpsertOne) AddOrganizationID(v uint64) *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *ContactUpsertOne) UpdateOrganizationID() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *ContactUpsertOne) ClearOrganizationID() *ContactUpsertOne {
	return u.Update(func(s *ContactUpsert) {
		s.ClearOrganizationID()
	})
}

// Exec executes the query.
func (u *ContactUpsertOne) Exec(ctx context.Context) error {
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for ContactCreate.OnConflict")
	}
	return u.create.Exec(ctx)
}

// ExecX is like Exec, but panics if an error occurs.
func (u *ContactUpsertOne) ExecX(ctx context.Context) {
	if err := u.create.Exec(ctx); err != nil {
		panic(err)
	}
}

// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *ContactUpsertOne) ID(ctx context.Context) (id uint64, err error) {
	node, err := u.create.Save(ctx)
	if err != nil {
		return id, err
	}
	return node.ID, nil
}

// IDX is like ID, but panics if an error occurs.
func (u *ContactUpsertOne) IDX(ctx context.Context) uint64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

// ContactCreateBulk is the builder for creating many Contact entities in bulk.
type ContactCreateBulk struct {
	config
	err      error
	builders []*ContactCreate
	conflict []sql.ConflictOption
}

// Save creates the Contact entities in the database.
func (ccb *ContactCreateBulk) Save(ctx context.Context) ([]*Contact, error) {
	if ccb.err != nil {
		return nil, ccb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
	nodes := make([]*Contact, len(ccb.builders))
	mutators := make([]Mutator, len(ccb.builders))
	for i := range ccb.builders {
		func(i int, root context.Context) {
			builder := ccb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*ContactMutation)
				if !ok {
					return nil, fmt.Errorf("unexpected mutation type %T", m)
				}
				if err := builder.check(); err != nil {
					return nil, err
				}
				builder.mutation = mutation
				var err error
				nodes[i], specs[i] = builder.createSpec()
				if i < len(mutators)-1 {
					_, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = ccb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, ccb.driver, spec); err != nil {
						if sqlgraph.IsConstraintError(err) {
							err = &ConstraintError{msg: err.Error(), wrap: err}
						}
					}
				}
				if err != nil {
					return nil, err
				}
				mutation.id = &nodes[i].ID
				if specs[i].ID.Value != nil && nodes[i].ID == 0 {
					id := specs[i].ID.Value.(int64)
					nodes[i].ID = uint64(id)
				}
				mutation.done = true
				return nodes[i], nil
			})
			for i := len(builder.hooks) - 1; i >= 0; i-- {
				mut = builder.hooks[i](mut)
			}
			mutators[i] = mut
		}(i, ctx)
	}
	if len(mutators) > 0 {
		if _, err := mutators[0].Mutate(ctx, ccb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

// SaveX is like Save, but panics if an error occurs.
func (ccb *ContactCreateBulk) SaveX(ctx context.Context) []*Contact {
	v, err := ccb.Save(ctx)
	if err != nil {
		panic(err)
	}
	return v
}

// Exec executes the query.
func (ccb *ContactCreateBulk) Exec(ctx context.Context) error {
	_, err := ccb.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (ccb *ContactCreateBulk) ExecX(ctx context.Context) {
	if err := ccb.Exec(ctx); err != nil {
		panic(err)
	}
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.Contact.CreateBulk(builders...).
//		OnConflict(
//			// Update the row with the new values
//			// the was proposed for insertion.
//			sql.ResolveWithNewValues(),
//		).
//		// Override some of the fields with custom
//		// update values.
//		Update(func(u *ent.ContactUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (ccb *ContactCreateBulk) OnConflict(opts ...sql.ConflictOption) *ContactUpsertBulk {
	ccb.conflict = opts
	return &ContactUpsertBulk{
		create: ccb,
	}
}

// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
//	client.Contact.Create().
//		OnConflict(sql.ConflictColumns(columns...)).
//		Exec(ctx)
func (ccb *ContactCreateBulk) OnConflictColumns(columns ...string) *ContactUpsertBulk {
	ccb.conflict = append(ccb.conflict, sql.ConflictColumns(columns...))
	return &ContactUpsertBulk{
		create: ccb,
	}
}

// ContactUpsertBulk is the builder for "upsert"-ing
// a bulk of Contact nodes.
type ContactUpsertBulk struct {
	create *ContactCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.Contact.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(contact.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *ContactUpsertBulk) UpdateNewValues() *ContactUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) {
		for _, b := range u.create.builders {
			if _, exists := b.mutation.ID(); exists {
				s.SetIgnore(contact.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(contact.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.Contact.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *ContactUpsertBulk) Ignore() *ContactUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
	return u
}

// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *ContactUpsertBulk) DoNothing() *ContactUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

// Update allows overriding fields `UPDATE` values. See the ContactCreateBulk.OnConflict
// documentation for more info.
func (u *ContactUpsertBulk) Update(set func(*ContactUpsert)) *ContactUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
		set(&ContactUpsert{UpdateSet: update})
	}))
	return u
}

// SetUpdatedAt sets the "updated_at" field.
func (u *ContactUpsertBulk) SetUpdatedAt(v time.Time) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetUpdatedAt(v)
	})
}

// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateUpdatedAt() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateUpdatedAt()
	})
}

// SetStatus sets the "status" field.
func (u *ContactUpsertBulk) SetStatus(v uint8) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetStatus(v)
	})
}

// AddStatus adds v to the "status" field.
func (u *ContactUpsertBulk) AddStatus(v uint8) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.AddStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateStatus() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateStatus()
	})
}

// ClearStatus clears the value of the "status" field.
func (u *ContactUpsertBulk) ClearStatus() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.ClearStatus()
	})
}

// SetDeletedAt sets the "deleted_at" field.
func (u *ContactUpsertBulk) SetDeletedAt(v time.Time) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetDeletedAt(v)
	})
}

// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateDeletedAt() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateDeletedAt()
	})
}

// ClearDeletedAt clears the value of the "deleted_at" field.
func (u *ContactUpsertBulk) ClearDeletedAt() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.ClearDeletedAt()
	})
}

// SetWxWxid sets the "wx_wxid" field.
func (u *ContactUpsertBulk) SetWxWxid(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetWxWxid(v)
	})
}

// UpdateWxWxid sets the "wx_wxid" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateWxWxid() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateWxWxid()
	})
}

// SetType sets the "type" field.
func (u *ContactUpsertBulk) SetType(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetType(v)
	})
}

// AddType adds v to the "type" field.
func (u *ContactUpsertBulk) AddType(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.AddType(v)
	})
}

// UpdateType sets the "type" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateType() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateType()
	})
}

// ClearType clears the value of the "type" field.
func (u *ContactUpsertBulk) ClearType() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.ClearType()
	})
}

// SetWxid sets the "wxid" field.
func (u *ContactUpsertBulk) SetWxid(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetWxid(v)
	})
}

// UpdateWxid sets the "wxid" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateWxid() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateWxid()
	})
}

// SetAccount sets the "account" field.
func (u *ContactUpsertBulk) SetAccount(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetAccount(v)
	})
}

// UpdateAccount sets the "account" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateAccount() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateAccount()
	})
}

// SetNickname sets the "nickname" field.
func (u *ContactUpsertBulk) SetNickname(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetNickname(v)
	})
}

// UpdateNickname sets the "nickname" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateNickname() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateNickname()
	})
}

// SetMarkname sets the "markname" field.
func (u *ContactUpsertBulk) SetMarkname(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetMarkname(v)
	})
}

// UpdateMarkname sets the "markname" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateMarkname() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateMarkname()
	})
}

// SetHeadimg sets the "headimg" field.
func (u *ContactUpsertBulk) SetHeadimg(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetHeadimg(v)
	})
}

// UpdateHeadimg sets the "headimg" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateHeadimg() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateHeadimg()
	})
}

// SetSex sets the "sex" field.
func (u *ContactUpsertBulk) SetSex(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetSex(v)
	})
}

// AddSex adds v to the "sex" field.
func (u *ContactUpsertBulk) AddSex(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.AddSex(v)
	})
}

// UpdateSex sets the "sex" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateSex() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateSex()
	})
}

// SetStarrole sets the "starrole" field.
func (u *ContactUpsertBulk) SetStarrole(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetStarrole(v)
	})
}

// UpdateStarrole sets the "starrole" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateStarrole() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateStarrole()
	})
}

// SetDontseeit sets the "dontseeit" field.
func (u *ContactUpsertBulk) SetDontseeit(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetDontseeit(v)
	})
}

// AddDontseeit adds v to the "dontseeit" field.
func (u *ContactUpsertBulk) AddDontseeit(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.AddDontseeit(v)
	})
}

// UpdateDontseeit sets the "dontseeit" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateDontseeit() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateDontseeit()
	})
}

// SetDontseeme sets the "dontseeme" field.
func (u *ContactUpsertBulk) SetDontseeme(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetDontseeme(v)
	})
}

// AddDontseeme adds v to the "dontseeme" field.
func (u *ContactUpsertBulk) AddDontseeme(v int) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.AddDontseeme(v)
	})
}

// UpdateDontseeme sets the "dontseeme" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateDontseeme() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateDontseeme()
	})
}

// SetLag sets the "lag" field.
func (u *ContactUpsertBulk) SetLag(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetLag(v)
	})
}

// UpdateLag sets the "lag" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateLag() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateLag()
	})
}

// SetGid sets the "gid" field.
func (u *ContactUpsertBulk) SetGid(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetGid(v)
	})
}

// UpdateGid sets the "gid" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateGid() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateGid()
	})
}

// SetGname sets the "gname" field.
func (u *ContactUpsertBulk) SetGname(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetGname(v)
	})
}

// UpdateGname sets the "gname" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateGname() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateGname()
	})
}

// SetV3 sets the "v3" field.
func (u *ContactUpsertBulk) SetV3(v string) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetV3(v)
	})
}

// UpdateV3 sets the "v3" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateV3() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateV3()
	})
}

// SetOrganizationID sets the "organization_id" field.
func (u *ContactUpsertBulk) SetOrganizationID(v uint64) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.SetOrganizationID(v)
	})
}

// AddOrganizationID adds v to the "organization_id" field.
func (u *ContactUpsertBulk) AddOrganizationID(v uint64) *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.AddOrganizationID(v)
	})
}

// UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
func (u *ContactUpsertBulk) UpdateOrganizationID() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.UpdateOrganizationID()
	})
}

// ClearOrganizationID clears the value of the "organization_id" field.
func (u *ContactUpsertBulk) ClearOrganizationID() *ContactUpsertBulk {
	return u.Update(func(s *ContactUpsert) {
		s.ClearOrganizationID()
	})
}

// Exec executes the query.
func (u *ContactUpsertBulk) Exec(ctx context.Context) error {
	if u.create.err != nil {
		return u.create.err
	}
	for i, b := range u.create.builders {
		if len(b.conflict) != 0 {
			return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the ContactCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for ContactCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

// ExecX is like Exec, but panics if an error occurs.
func (u *ContactUpsertBulk) ExecX(ctx context.Context) {
	if err := u.create.Exec(ctx); err != nil {
		panic(err)
	}
}
