// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/member-gentei/member-gentei/gentei/ent/guildrole"
	"github.com/member-gentei/member-gentei/gentei/ent/user"
	"github.com/member-gentei/member-gentei/gentei/ent/usermembership"
	"github.com/member-gentei/member-gentei/gentei/ent/youtubetalent"
)

// UserMembershipCreate is the builder for creating a UserMembership entity.
type UserMembershipCreate struct {
	config
	mutation *UserMembershipMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetFirstFailed sets the "first_failed" field.
func (umc *UserMembershipCreate) SetFirstFailed(t time.Time) *UserMembershipCreate {
	umc.mutation.SetFirstFailed(t)
	return umc
}

// SetNillableFirstFailed sets the "first_failed" field if the given value is not nil.
func (umc *UserMembershipCreate) SetNillableFirstFailed(t *time.Time) *UserMembershipCreate {
	if t != nil {
		umc.SetFirstFailed(*t)
	}
	return umc
}

// SetLastVerified sets the "last_verified" field.
func (umc *UserMembershipCreate) SetLastVerified(t time.Time) *UserMembershipCreate {
	umc.mutation.SetLastVerified(t)
	return umc
}

// SetFailCount sets the "fail_count" field.
func (umc *UserMembershipCreate) SetFailCount(i int) *UserMembershipCreate {
	umc.mutation.SetFailCount(i)
	return umc
}

// SetNillableFailCount sets the "fail_count" field if the given value is not nil.
func (umc *UserMembershipCreate) SetNillableFailCount(i *int) *UserMembershipCreate {
	if i != nil {
		umc.SetFailCount(*i)
	}
	return umc
}

// SetUserID sets the "user" edge to the User entity by ID.
func (umc *UserMembershipCreate) SetUserID(id uint64) *UserMembershipCreate {
	umc.mutation.SetUserID(id)
	return umc
}

// SetNillableUserID sets the "user" edge to the User entity by ID if the given value is not nil.
func (umc *UserMembershipCreate) SetNillableUserID(id *uint64) *UserMembershipCreate {
	if id != nil {
		umc = umc.SetUserID(*id)
	}
	return umc
}

// SetUser sets the "user" edge to the User entity.
func (umc *UserMembershipCreate) SetUser(u *User) *UserMembershipCreate {
	return umc.SetUserID(u.ID)
}

// SetYoutubeTalentID sets the "youtube_talent" edge to the YouTubeTalent entity by ID.
func (umc *UserMembershipCreate) SetYoutubeTalentID(id string) *UserMembershipCreate {
	umc.mutation.SetYoutubeTalentID(id)
	return umc
}

// SetYoutubeTalent sets the "youtube_talent" edge to the YouTubeTalent entity.
func (umc *UserMembershipCreate) SetYoutubeTalent(y *YouTubeTalent) *UserMembershipCreate {
	return umc.SetYoutubeTalentID(y.ID)
}

// AddRoleIDs adds the "roles" edge to the GuildRole entity by IDs.
func (umc *UserMembershipCreate) AddRoleIDs(ids ...uint64) *UserMembershipCreate {
	umc.mutation.AddRoleIDs(ids...)
	return umc
}

// AddRoles adds the "roles" edges to the GuildRole entity.
func (umc *UserMembershipCreate) AddRoles(g ...*GuildRole) *UserMembershipCreate {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return umc.AddRoleIDs(ids...)
}

// Mutation returns the UserMembershipMutation object of the builder.
func (umc *UserMembershipCreate) Mutation() *UserMembershipMutation {
	return umc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (umc *UserMembershipCreate) defaults() {
	if _, ok := umc.mutation.FailCount(); !ok {
		v := usermembership.DefaultFailCount
		umc.mutation.SetFailCount(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (umc *UserMembershipCreate) check() error {
	if _, ok := umc.mutation.LastVerified(); !ok {
		return &ValidationError{Name: "last_verified", err: errors.New(`ent: missing required field "UserMembership.last_verified"`)}
	}
	if _, ok := umc.mutation.FailCount(); !ok {
		return &ValidationError{Name: "fail_count", err: errors.New(`ent: missing required field "UserMembership.fail_count"`)}
	}
	if len(umc.mutation.YoutubeTalentIDs()) == 0 {
		return &ValidationError{Name: "youtube_talent", err: errors.New(`ent: missing required edge "UserMembership.youtube_talent"`)}
	}
	return nil
}

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

func (umc *UserMembershipCreate) createSpec() (*UserMembership, *sqlgraph.CreateSpec) {
	var (
		_node = &UserMembership{config: umc.config}
		_spec = sqlgraph.NewCreateSpec(usermembership.Table, sqlgraph.NewFieldSpec(usermembership.FieldID, field.TypeInt))
	)
	_spec.OnConflict = umc.conflict
	if value, ok := umc.mutation.FirstFailed(); ok {
		_spec.SetField(usermembership.FieldFirstFailed, field.TypeTime, value)
		_node.FirstFailed = value
	}
	if value, ok := umc.mutation.LastVerified(); ok {
		_spec.SetField(usermembership.FieldLastVerified, field.TypeTime, value)
		_node.LastVerified = value
	}
	if value, ok := umc.mutation.FailCount(); ok {
		_spec.SetField(usermembership.FieldFailCount, field.TypeInt, value)
		_node.FailCount = value
	}
	if nodes := umc.mutation.UserIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   usermembership.UserTable,
			Columns: []string{usermembership.UserColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.user_memberships = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := umc.mutation.YoutubeTalentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   usermembership.YoutubeTalentTable,
			Columns: []string{usermembership.YoutubeTalentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(youtubetalent.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.user_membership_youtube_talent = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := umc.mutation.RolesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   usermembership.RolesTable,
			Columns: usermembership.RolesPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guildrole.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.UserMembership.Create().
//		SetFirstFailed(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.UserMembershipUpsert) {
//			SetFirstFailed(v+v).
//		}).
//		Exec(ctx)
func (umc *UserMembershipCreate) OnConflict(opts ...sql.ConflictOption) *UserMembershipUpsertOne {
	umc.conflict = opts
	return &UserMembershipUpsertOne{
		create: umc,
	}
}

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

type (
	// UserMembershipUpsertOne is the builder for "upsert"-ing
	//  one UserMembership node.
	UserMembershipUpsertOne struct {
		create *UserMembershipCreate
	}

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

// SetFirstFailed sets the "first_failed" field.
func (u *UserMembershipUpsert) SetFirstFailed(v time.Time) *UserMembershipUpsert {
	u.Set(usermembership.FieldFirstFailed, v)
	return u
}

// UpdateFirstFailed sets the "first_failed" field to the value that was provided on create.
func (u *UserMembershipUpsert) UpdateFirstFailed() *UserMembershipUpsert {
	u.SetExcluded(usermembership.FieldFirstFailed)
	return u
}

// ClearFirstFailed clears the value of the "first_failed" field.
func (u *UserMembershipUpsert) ClearFirstFailed() *UserMembershipUpsert {
	u.SetNull(usermembership.FieldFirstFailed)
	return u
}

// SetLastVerified sets the "last_verified" field.
func (u *UserMembershipUpsert) SetLastVerified(v time.Time) *UserMembershipUpsert {
	u.Set(usermembership.FieldLastVerified, v)
	return u
}

// UpdateLastVerified sets the "last_verified" field to the value that was provided on create.
func (u *UserMembershipUpsert) UpdateLastVerified() *UserMembershipUpsert {
	u.SetExcluded(usermembership.FieldLastVerified)
	return u
}

// SetFailCount sets the "fail_count" field.
func (u *UserMembershipUpsert) SetFailCount(v int) *UserMembershipUpsert {
	u.Set(usermembership.FieldFailCount, v)
	return u
}

// UpdateFailCount sets the "fail_count" field to the value that was provided on create.
func (u *UserMembershipUpsert) UpdateFailCount() *UserMembershipUpsert {
	u.SetExcluded(usermembership.FieldFailCount)
	return u
}

// AddFailCount adds v to the "fail_count" field.
func (u *UserMembershipUpsert) AddFailCount(v int) *UserMembershipUpsert {
	u.Add(usermembership.FieldFailCount, v)
	return u
}

// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
//	client.UserMembership.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *UserMembershipUpsertOne) UpdateNewValues() *UserMembershipUpsertOne {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	return u
}

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

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

// SetFirstFailed sets the "first_failed" field.
func (u *UserMembershipUpsertOne) SetFirstFailed(v time.Time) *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.SetFirstFailed(v)
	})
}

// UpdateFirstFailed sets the "first_failed" field to the value that was provided on create.
func (u *UserMembershipUpsertOne) UpdateFirstFailed() *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.UpdateFirstFailed()
	})
}

// ClearFirstFailed clears the value of the "first_failed" field.
func (u *UserMembershipUpsertOne) ClearFirstFailed() *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.ClearFirstFailed()
	})
}

// SetLastVerified sets the "last_verified" field.
func (u *UserMembershipUpsertOne) SetLastVerified(v time.Time) *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.SetLastVerified(v)
	})
}

// UpdateLastVerified sets the "last_verified" field to the value that was provided on create.
func (u *UserMembershipUpsertOne) UpdateLastVerified() *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.UpdateLastVerified()
	})
}

// SetFailCount sets the "fail_count" field.
func (u *UserMembershipUpsertOne) SetFailCount(v int) *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.SetFailCount(v)
	})
}

// AddFailCount adds v to the "fail_count" field.
func (u *UserMembershipUpsertOne) AddFailCount(v int) *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.AddFailCount(v)
	})
}

// UpdateFailCount sets the "fail_count" field to the value that was provided on create.
func (u *UserMembershipUpsertOne) UpdateFailCount() *UserMembershipUpsertOne {
	return u.Update(func(s *UserMembershipUpsert) {
		s.UpdateFailCount()
	})
}

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

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

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.UserMembership.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.UserMembershipUpsert) {
//			SetFirstFailed(v+v).
//		}).
//		Exec(ctx)
func (umcb *UserMembershipCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserMembershipUpsertBulk {
	umcb.conflict = opts
	return &UserMembershipUpsertBulk{
		create: umcb,
	}
}

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

// UserMembershipUpsertBulk is the builder for "upsert"-ing
// a bulk of UserMembership nodes.
type UserMembershipUpsertBulk struct {
	create *UserMembershipCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.UserMembership.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//		).
//		Exec(ctx)
func (u *UserMembershipUpsertBulk) UpdateNewValues() *UserMembershipUpsertBulk {
	u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
	return u
}

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

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

// SetFirstFailed sets the "first_failed" field.
func (u *UserMembershipUpsertBulk) SetFirstFailed(v time.Time) *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.SetFirstFailed(v)
	})
}

// UpdateFirstFailed sets the "first_failed" field to the value that was provided on create.
func (u *UserMembershipUpsertBulk) UpdateFirstFailed() *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.UpdateFirstFailed()
	})
}

// ClearFirstFailed clears the value of the "first_failed" field.
func (u *UserMembershipUpsertBulk) ClearFirstFailed() *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.ClearFirstFailed()
	})
}

// SetLastVerified sets the "last_verified" field.
func (u *UserMembershipUpsertBulk) SetLastVerified(v time.Time) *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.SetLastVerified(v)
	})
}

// UpdateLastVerified sets the "last_verified" field to the value that was provided on create.
func (u *UserMembershipUpsertBulk) UpdateLastVerified() *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.UpdateLastVerified()
	})
}

// SetFailCount sets the "fail_count" field.
func (u *UserMembershipUpsertBulk) SetFailCount(v int) *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.SetFailCount(v)
	})
}

// AddFailCount adds v to the "fail_count" field.
func (u *UserMembershipUpsertBulk) AddFailCount(v int) *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.AddFailCount(v)
	})
}

// UpdateFailCount sets the "fail_count" field to the value that was provided on create.
func (u *UserMembershipUpsertBulk) UpdateFailCount() *UserMembershipUpsertBulk {
	return u.Update(func(s *UserMembershipUpsert) {
		s.UpdateFailCount()
	})
}

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

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