// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"
	"wechat-api/ent/wpchatroommember"

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

// WpChatroomMemberCreate is the builder for creating a WpChatroomMember entity.
type WpChatroomMemberCreate struct {
	config
	mutation *WpChatroomMemberMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

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

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

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

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

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

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

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

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

// SetAvatar sets the "avatar" field.
func (wcmc *WpChatroomMemberCreate) SetAvatar(s string) *WpChatroomMemberCreate {
	wcmc.mutation.SetAvatar(s)
	return wcmc
}

// SetNillableAvatar sets the "avatar" field if the given value is not nil.
func (wcmc *WpChatroomMemberCreate) SetNillableAvatar(s *string) *WpChatroomMemberCreate {
	if s != nil {
		wcmc.SetAvatar(*s)
	}
	return wcmc
}

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

// Mutation returns the WpChatroomMemberMutation object of the builder.
func (wcmc *WpChatroomMemberCreate) Mutation() *WpChatroomMemberMutation {
	return wcmc.mutation
}

// Save creates the WpChatroomMember in the database.
func (wcmc *WpChatroomMemberCreate) Save(ctx context.Context) (*WpChatroomMember, error) {
	wcmc.defaults()
	return withHooks(ctx, wcmc.sqlSave, wcmc.mutation, wcmc.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (wcmc *WpChatroomMemberCreate) defaults() {
	if _, ok := wcmc.mutation.CreatedAt(); !ok {
		v := wpchatroommember.DefaultCreatedAt()
		wcmc.mutation.SetCreatedAt(v)
	}
	if _, ok := wcmc.mutation.UpdatedAt(); !ok {
		v := wpchatroommember.DefaultUpdatedAt()
		wcmc.mutation.SetUpdatedAt(v)
	}
	if _, ok := wcmc.mutation.Status(); !ok {
		v := wpchatroommember.DefaultStatus
		wcmc.mutation.SetStatus(v)
	}
	if _, ok := wcmc.mutation.WxWxid(); !ok {
		v := wpchatroommember.DefaultWxWxid
		wcmc.mutation.SetWxWxid(v)
	}
	if _, ok := wcmc.mutation.Wxid(); !ok {
		v := wpchatroommember.DefaultWxid
		wcmc.mutation.SetWxid(v)
	}
	if _, ok := wcmc.mutation.Nickname(); !ok {
		v := wpchatroommember.DefaultNickname
		wcmc.mutation.SetNickname(v)
	}
	if _, ok := wcmc.mutation.Avatar(); !ok {
		v := wpchatroommember.DefaultAvatar
		wcmc.mutation.SetAvatar(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (wcmc *WpChatroomMemberCreate) check() error {
	if _, ok := wcmc.mutation.CreatedAt(); !ok {
		return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WpChatroomMember.created_at"`)}
	}
	if _, ok := wcmc.mutation.UpdatedAt(); !ok {
		return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WpChatroomMember.updated_at"`)}
	}
	if _, ok := wcmc.mutation.WxWxid(); !ok {
		return &ValidationError{Name: "wx_wxid", err: errors.New(`ent: missing required field "WpChatroomMember.wx_wxid"`)}
	}
	if _, ok := wcmc.mutation.Wxid(); !ok {
		return &ValidationError{Name: "wxid", err: errors.New(`ent: missing required field "WpChatroomMember.wxid"`)}
	}
	if _, ok := wcmc.mutation.Nickname(); !ok {
		return &ValidationError{Name: "nickname", err: errors.New(`ent: missing required field "WpChatroomMember.nickname"`)}
	}
	if _, ok := wcmc.mutation.Avatar(); !ok {
		return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "WpChatroomMember.avatar"`)}
	}
	return nil
}

func (wcmc *WpChatroomMemberCreate) sqlSave(ctx context.Context) (*WpChatroomMember, error) {
	if err := wcmc.check(); err != nil {
		return nil, err
	}
	_node, _spec := wcmc.createSpec()
	if err := sqlgraph.CreateNode(ctx, wcmc.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)
	}
	wcmc.mutation.id = &_node.ID
	wcmc.mutation.done = true
	return _node, nil
}

func (wcmc *WpChatroomMemberCreate) createSpec() (*WpChatroomMember, *sqlgraph.CreateSpec) {
	var (
		_node = &WpChatroomMember{config: wcmc.config}
		_spec = sqlgraph.NewCreateSpec(wpchatroommember.Table, sqlgraph.NewFieldSpec(wpchatroommember.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = wcmc.conflict
	if id, ok := wcmc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := wcmc.mutation.CreatedAt(); ok {
		_spec.SetField(wpchatroommember.FieldCreatedAt, field.TypeTime, value)
		_node.CreatedAt = value
	}
	if value, ok := wcmc.mutation.UpdatedAt(); ok {
		_spec.SetField(wpchatroommember.FieldUpdatedAt, field.TypeTime, value)
		_node.UpdatedAt = value
	}
	if value, ok := wcmc.mutation.Status(); ok {
		_spec.SetField(wpchatroommember.FieldStatus, field.TypeUint8, value)
		_node.Status = value
	}
	if value, ok := wcmc.mutation.WxWxid(); ok {
		_spec.SetField(wpchatroommember.FieldWxWxid, field.TypeString, value)
		_node.WxWxid = value
	}
	if value, ok := wcmc.mutation.Wxid(); ok {
		_spec.SetField(wpchatroommember.FieldWxid, field.TypeString, value)
		_node.Wxid = value
	}
	if value, ok := wcmc.mutation.Nickname(); ok {
		_spec.SetField(wpchatroommember.FieldNickname, field.TypeString, value)
		_node.Nickname = value
	}
	if value, ok := wcmc.mutation.Avatar(); ok {
		_spec.SetField(wpchatroommember.FieldAvatar, field.TypeString, value)
		_node.Avatar = value
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WpChatroomMember.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.WpChatroomMemberUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (wcmc *WpChatroomMemberCreate) OnConflict(opts ...sql.ConflictOption) *WpChatroomMemberUpsertOne {
	wcmc.conflict = opts
	return &WpChatroomMemberUpsertOne{
		create: wcmc,
	}
}

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

type (
	// WpChatroomMemberUpsertOne is the builder for "upsert"-ing
	//  one WpChatroomMember node.
	WpChatroomMemberUpsertOne struct {
		create *WpChatroomMemberCreate
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

// SetAvatar sets the "avatar" field.
func (u *WpChatroomMemberUpsert) SetAvatar(v string) *WpChatroomMemberUpsert {
	u.Set(wpchatroommember.FieldAvatar, v)
	return u
}

// UpdateAvatar sets the "avatar" field to the value that was provided on create.
func (u *WpChatroomMemberUpsert) UpdateAvatar() *WpChatroomMemberUpsert {
	u.SetExcluded(wpchatroommember.FieldAvatar)
	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.WpChatroomMember.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(wpchatroommember.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WpChatroomMemberUpsertOne) UpdateNewValues() *WpChatroomMemberUpsertOne {
	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(wpchatroommember.FieldID)
		}
		if _, exists := u.create.mutation.CreatedAt(); exists {
			s.SetIgnore(wpchatroommember.FieldCreatedAt)
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.WpChatroomMember.Create().
//	    OnConflict(sql.ResolveWithIgnore()).
//	    Exec(ctx)
func (u *WpChatroomMemberUpsertOne) Ignore() *WpChatroomMemberUpsertOne {
	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 *WpChatroomMemberUpsertOne) DoNothing() *WpChatroomMemberUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

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

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

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

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

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

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

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

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

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

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

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

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

// SetAvatar sets the "avatar" field.
func (u *WpChatroomMemberUpsertOne) SetAvatar(v string) *WpChatroomMemberUpsertOne {
	return u.Update(func(s *WpChatroomMemberUpsert) {
		s.SetAvatar(v)
	})
}

// UpdateAvatar sets the "avatar" field to the value that was provided on create.
func (u *WpChatroomMemberUpsertOne) UpdateAvatar() *WpChatroomMemberUpsertOne {
	return u.Update(func(s *WpChatroomMemberUpsert) {
		s.UpdateAvatar()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *WpChatroomMemberUpsertOne) 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 *WpChatroomMemberUpsertOne) 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 *WpChatroomMemberUpsertOne) IDX(ctx context.Context) uint64 {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

// Save creates the WpChatroomMember entities in the database.
func (wcmcb *WpChatroomMemberCreateBulk) Save(ctx context.Context) ([]*WpChatroomMember, error) {
	if wcmcb.err != nil {
		return nil, wcmcb.err
	}
	specs := make([]*sqlgraph.CreateSpec, len(wcmcb.builders))
	nodes := make([]*WpChatroomMember, len(wcmcb.builders))
	mutators := make([]Mutator, len(wcmcb.builders))
	for i := range wcmcb.builders {
		func(i int, root context.Context) {
			builder := wcmcb.builders[i]
			builder.defaults()
			var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
				mutation, ok := m.(*WpChatroomMemberMutation)
				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, wcmcb.builders[i+1].mutation)
				} else {
					spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
					spec.OnConflict = wcmcb.conflict
					// Invoke the actual operation on the latest mutation in the chain.
					if err = sqlgraph.BatchCreate(ctx, wcmcb.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, wcmcb.builders[0].mutation); err != nil {
			return nil, err
		}
	}
	return nodes, nil
}

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.WpChatroomMember.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.WpChatroomMemberUpsert) {
//			SetCreatedAt(v+v).
//		}).
//		Exec(ctx)
func (wcmcb *WpChatroomMemberCreateBulk) OnConflict(opts ...sql.ConflictOption) *WpChatroomMemberUpsertBulk {
	wcmcb.conflict = opts
	return &WpChatroomMemberUpsertBulk{
		create: wcmcb,
	}
}

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

// WpChatroomMemberUpsertBulk is the builder for "upsert"-ing
// a bulk of WpChatroomMember nodes.
type WpChatroomMemberUpsertBulk struct {
	create *WpChatroomMemberCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.WpChatroomMember.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(wpchatroommember.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *WpChatroomMemberUpsertBulk) UpdateNewValues() *WpChatroomMemberUpsertBulk {
	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(wpchatroommember.FieldID)
			}
			if _, exists := b.mutation.CreatedAt(); exists {
				s.SetIgnore(wpchatroommember.FieldCreatedAt)
			}
		}
	}))
	return u
}

// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
//	client.WpChatroomMember.Create().
//		OnConflict(sql.ResolveWithIgnore()).
//		Exec(ctx)
func (u *WpChatroomMemberUpsertBulk) Ignore() *WpChatroomMemberUpsertBulk {
	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 *WpChatroomMemberUpsertBulk) DoNothing() *WpChatroomMemberUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.DoNothing())
	return u
}

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

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

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

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

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

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

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

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

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

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

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

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

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

// SetAvatar sets the "avatar" field.
func (u *WpChatroomMemberUpsertBulk) SetAvatar(v string) *WpChatroomMemberUpsertBulk {
	return u.Update(func(s *WpChatroomMemberUpsert) {
		s.SetAvatar(v)
	})
}

// UpdateAvatar sets the "avatar" field to the value that was provided on create.
func (u *WpChatroomMemberUpsertBulk) UpdateAvatar() *WpChatroomMemberUpsertBulk {
	return u.Update(func(s *WpChatroomMemberUpsert) {
		s.UpdateAvatar()
	})
}

// Exec executes the query.
func (u *WpChatroomMemberUpsertBulk) 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 WpChatroomMemberCreateBulk instead", i)
		}
	}
	if len(u.create.conflict) == 0 {
		return errors.New("ent: missing options for WpChatroomMemberCreateBulk.OnConflict")
	}
	return u.create.Exec(ctx)
}

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