// 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/guild"
	"github.com/member-gentei/member-gentei/gentei/ent/user"
	"github.com/member-gentei/member-gentei/gentei/ent/usermembership"
	"golang.org/x/oauth2"
)

// UserCreate is the builder for creating a User entity.
type UserCreate struct {
	config
	mutation *UserMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetFullName sets the "full_name" field.
func (uc *UserCreate) SetFullName(s string) *UserCreate {
	uc.mutation.SetFullName(s)
	return uc
}

// SetAvatarHash sets the "avatar_hash" field.
func (uc *UserCreate) SetAvatarHash(s string) *UserCreate {
	uc.mutation.SetAvatarHash(s)
	return uc
}

// SetLastCheck sets the "last_check" field.
func (uc *UserCreate) SetLastCheck(t time.Time) *UserCreate {
	uc.mutation.SetLastCheck(t)
	return uc
}

// SetNillableLastCheck sets the "last_check" field if the given value is not nil.
func (uc *UserCreate) SetNillableLastCheck(t *time.Time) *UserCreate {
	if t != nil {
		uc.SetLastCheck(*t)
	}
	return uc
}

// SetYoutubeID sets the "youtube_id" field.
func (uc *UserCreate) SetYoutubeID(s string) *UserCreate {
	uc.mutation.SetYoutubeID(s)
	return uc
}

// SetNillableYoutubeID sets the "youtube_id" field if the given value is not nil.
func (uc *UserCreate) SetNillableYoutubeID(s *string) *UserCreate {
	if s != nil {
		uc.SetYoutubeID(*s)
	}
	return uc
}

// SetYoutubeToken sets the "youtube_token" field.
func (uc *UserCreate) SetYoutubeToken(o *oauth2.Token) *UserCreate {
	uc.mutation.SetYoutubeToken(o)
	return uc
}

// SetDiscordToken sets the "discord_token" field.
func (uc *UserCreate) SetDiscordToken(o *oauth2.Token) *UserCreate {
	uc.mutation.SetDiscordToken(o)
	return uc
}

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

// AddGuildIDs adds the "guilds" edge to the Guild entity by IDs.
func (uc *UserCreate) AddGuildIDs(ids ...uint64) *UserCreate {
	uc.mutation.AddGuildIDs(ids...)
	return uc
}

// AddGuilds adds the "guilds" edges to the Guild entity.
func (uc *UserCreate) AddGuilds(g ...*Guild) *UserCreate {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return uc.AddGuildIDs(ids...)
}

// AddGuildsAdminIDs adds the "guilds_admin" edge to the Guild entity by IDs.
func (uc *UserCreate) AddGuildsAdminIDs(ids ...uint64) *UserCreate {
	uc.mutation.AddGuildsAdminIDs(ids...)
	return uc
}

// AddGuildsAdmin adds the "guilds_admin" edges to the Guild entity.
func (uc *UserCreate) AddGuildsAdmin(g ...*Guild) *UserCreate {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return uc.AddGuildsAdminIDs(ids...)
}

// AddMembershipIDs adds the "memberships" edge to the UserMembership entity by IDs.
func (uc *UserCreate) AddMembershipIDs(ids ...int) *UserCreate {
	uc.mutation.AddMembershipIDs(ids...)
	return uc
}

// AddMemberships adds the "memberships" edges to the UserMembership entity.
func (uc *UserCreate) AddMemberships(u ...*UserMembership) *UserCreate {
	ids := make([]int, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return uc.AddMembershipIDs(ids...)
}

// Mutation returns the UserMutation object of the builder.
func (uc *UserCreate) Mutation() *UserMutation {
	return uc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (uc *UserCreate) defaults() {
	if _, ok := uc.mutation.LastCheck(); !ok {
		v := user.DefaultLastCheck()
		uc.mutation.SetLastCheck(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (uc *UserCreate) check() error {
	if _, ok := uc.mutation.FullName(); !ok {
		return &ValidationError{Name: "full_name", err: errors.New(`ent: missing required field "User.full_name"`)}
	}
	if _, ok := uc.mutation.AvatarHash(); !ok {
		return &ValidationError{Name: "avatar_hash", err: errors.New(`ent: missing required field "User.avatar_hash"`)}
	}
	if _, ok := uc.mutation.LastCheck(); !ok {
		return &ValidationError{Name: "last_check", err: errors.New(`ent: missing required field "User.last_check"`)}
	}
	return nil
}

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

func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
	var (
		_node = &User{config: uc.config}
		_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeUint64))
	)
	_spec.OnConflict = uc.conflict
	if id, ok := uc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := uc.mutation.FullName(); ok {
		_spec.SetField(user.FieldFullName, field.TypeString, value)
		_node.FullName = value
	}
	if value, ok := uc.mutation.AvatarHash(); ok {
		_spec.SetField(user.FieldAvatarHash, field.TypeString, value)
		_node.AvatarHash = value
	}
	if value, ok := uc.mutation.LastCheck(); ok {
		_spec.SetField(user.FieldLastCheck, field.TypeTime, value)
		_node.LastCheck = value
	}
	if value, ok := uc.mutation.YoutubeID(); ok {
		_spec.SetField(user.FieldYoutubeID, field.TypeString, value)
		_node.YoutubeID = &value
	}
	if value, ok := uc.mutation.YoutubeToken(); ok {
		_spec.SetField(user.FieldYoutubeToken, field.TypeJSON, value)
		_node.YoutubeToken = value
	}
	if value, ok := uc.mutation.DiscordToken(); ok {
		_spec.SetField(user.FieldDiscordToken, field.TypeJSON, value)
		_node.DiscordToken = value
	}
	if nodes := uc.mutation.GuildsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   user.GuildsTable,
			Columns: user.GuildsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guild.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := uc.mutation.GuildsAdminIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   user.GuildsAdminTable,
			Columns: user.GuildsAdminPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guild.FieldID, field.TypeUint64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := uc.mutation.MembershipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   user.MembershipsTable,
			Columns: []string{user.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usermembership.FieldID, field.TypeInt),
			},
		}
		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.User.Create().
//		SetFullName(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.UserUpsert) {
//			SetFullName(v+v).
//		}).
//		Exec(ctx)
func (uc *UserCreate) OnConflict(opts ...sql.ConflictOption) *UserUpsertOne {
	uc.conflict = opts
	return &UserUpsertOne{
		create: uc,
	}
}

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

type (
	// UserUpsertOne is the builder for "upsert"-ing
	//  one User node.
	UserUpsertOne struct {
		create *UserCreate
	}

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

// SetFullName sets the "full_name" field.
func (u *UserUpsert) SetFullName(v string) *UserUpsert {
	u.Set(user.FieldFullName, v)
	return u
}

// UpdateFullName sets the "full_name" field to the value that was provided on create.
func (u *UserUpsert) UpdateFullName() *UserUpsert {
	u.SetExcluded(user.FieldFullName)
	return u
}

// SetAvatarHash sets the "avatar_hash" field.
func (u *UserUpsert) SetAvatarHash(v string) *UserUpsert {
	u.Set(user.FieldAvatarHash, v)
	return u
}

// UpdateAvatarHash sets the "avatar_hash" field to the value that was provided on create.
func (u *UserUpsert) UpdateAvatarHash() *UserUpsert {
	u.SetExcluded(user.FieldAvatarHash)
	return u
}

// SetLastCheck sets the "last_check" field.
func (u *UserUpsert) SetLastCheck(v time.Time) *UserUpsert {
	u.Set(user.FieldLastCheck, v)
	return u
}

// UpdateLastCheck sets the "last_check" field to the value that was provided on create.
func (u *UserUpsert) UpdateLastCheck() *UserUpsert {
	u.SetExcluded(user.FieldLastCheck)
	return u
}

// SetYoutubeID sets the "youtube_id" field.
func (u *UserUpsert) SetYoutubeID(v string) *UserUpsert {
	u.Set(user.FieldYoutubeID, v)
	return u
}

// UpdateYoutubeID sets the "youtube_id" field to the value that was provided on create.
func (u *UserUpsert) UpdateYoutubeID() *UserUpsert {
	u.SetExcluded(user.FieldYoutubeID)
	return u
}

// ClearYoutubeID clears the value of the "youtube_id" field.
func (u *UserUpsert) ClearYoutubeID() *UserUpsert {
	u.SetNull(user.FieldYoutubeID)
	return u
}

// SetYoutubeToken sets the "youtube_token" field.
func (u *UserUpsert) SetYoutubeToken(v *oauth2.Token) *UserUpsert {
	u.Set(user.FieldYoutubeToken, v)
	return u
}

// UpdateYoutubeToken sets the "youtube_token" field to the value that was provided on create.
func (u *UserUpsert) UpdateYoutubeToken() *UserUpsert {
	u.SetExcluded(user.FieldYoutubeToken)
	return u
}

// ClearYoutubeToken clears the value of the "youtube_token" field.
func (u *UserUpsert) ClearYoutubeToken() *UserUpsert {
	u.SetNull(user.FieldYoutubeToken)
	return u
}

// SetDiscordToken sets the "discord_token" field.
func (u *UserUpsert) SetDiscordToken(v *oauth2.Token) *UserUpsert {
	u.Set(user.FieldDiscordToken, v)
	return u
}

// UpdateDiscordToken sets the "discord_token" field to the value that was provided on create.
func (u *UserUpsert) UpdateDiscordToken() *UserUpsert {
	u.SetExcluded(user.FieldDiscordToken)
	return u
}

// ClearDiscordToken clears the value of the "discord_token" field.
func (u *UserUpsert) ClearDiscordToken() *UserUpsert {
	u.SetNull(user.FieldDiscordToken)
	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.User.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(user.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UserUpsertOne) UpdateNewValues() *UserUpsertOne {
	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(user.FieldID)
		}
	}))
	return u
}

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

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

// SetFullName sets the "full_name" field.
func (u *UserUpsertOne) SetFullName(v string) *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.SetFullName(v)
	})
}

// UpdateFullName sets the "full_name" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateFullName() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.UpdateFullName()
	})
}

// SetAvatarHash sets the "avatar_hash" field.
func (u *UserUpsertOne) SetAvatarHash(v string) *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.SetAvatarHash(v)
	})
}

// UpdateAvatarHash sets the "avatar_hash" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateAvatarHash() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.UpdateAvatarHash()
	})
}

// SetLastCheck sets the "last_check" field.
func (u *UserUpsertOne) SetLastCheck(v time.Time) *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.SetLastCheck(v)
	})
}

// UpdateLastCheck sets the "last_check" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateLastCheck() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.UpdateLastCheck()
	})
}

// SetYoutubeID sets the "youtube_id" field.
func (u *UserUpsertOne) SetYoutubeID(v string) *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.SetYoutubeID(v)
	})
}

// UpdateYoutubeID sets the "youtube_id" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateYoutubeID() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.UpdateYoutubeID()
	})
}

// ClearYoutubeID clears the value of the "youtube_id" field.
func (u *UserUpsertOne) ClearYoutubeID() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.ClearYoutubeID()
	})
}

// SetYoutubeToken sets the "youtube_token" field.
func (u *UserUpsertOne) SetYoutubeToken(v *oauth2.Token) *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.SetYoutubeToken(v)
	})
}

// UpdateYoutubeToken sets the "youtube_token" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateYoutubeToken() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.UpdateYoutubeToken()
	})
}

// ClearYoutubeToken clears the value of the "youtube_token" field.
func (u *UserUpsertOne) ClearYoutubeToken() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.ClearYoutubeToken()
	})
}

// SetDiscordToken sets the "discord_token" field.
func (u *UserUpsertOne) SetDiscordToken(v *oauth2.Token) *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.SetDiscordToken(v)
	})
}

// UpdateDiscordToken sets the "discord_token" field to the value that was provided on create.
func (u *UserUpsertOne) UpdateDiscordToken() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.UpdateDiscordToken()
	})
}

// ClearDiscordToken clears the value of the "discord_token" field.
func (u *UserUpsertOne) ClearDiscordToken() *UserUpsertOne {
	return u.Update(func(s *UserUpsert) {
		s.ClearDiscordToken()
	})
}

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

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

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.User.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.UserUpsert) {
//			SetFullName(v+v).
//		}).
//		Exec(ctx)
func (ucb *UserCreateBulk) OnConflict(opts ...sql.ConflictOption) *UserUpsertBulk {
	ucb.conflict = opts
	return &UserUpsertBulk{
		create: ucb,
	}
}

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

// UserUpsertBulk is the builder for "upsert"-ing
// a bulk of User nodes.
type UserUpsertBulk struct {
	create *UserCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.User.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(user.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *UserUpsertBulk) UpdateNewValues() *UserUpsertBulk {
	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(user.FieldID)
			}
		}
	}))
	return u
}

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

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

// SetFullName sets the "full_name" field.
func (u *UserUpsertBulk) SetFullName(v string) *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.SetFullName(v)
	})
}

// UpdateFullName sets the "full_name" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateFullName() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.UpdateFullName()
	})
}

// SetAvatarHash sets the "avatar_hash" field.
func (u *UserUpsertBulk) SetAvatarHash(v string) *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.SetAvatarHash(v)
	})
}

// UpdateAvatarHash sets the "avatar_hash" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateAvatarHash() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.UpdateAvatarHash()
	})
}

// SetLastCheck sets the "last_check" field.
func (u *UserUpsertBulk) SetLastCheck(v time.Time) *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.SetLastCheck(v)
	})
}

// UpdateLastCheck sets the "last_check" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateLastCheck() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.UpdateLastCheck()
	})
}

// SetYoutubeID sets the "youtube_id" field.
func (u *UserUpsertBulk) SetYoutubeID(v string) *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.SetYoutubeID(v)
	})
}

// UpdateYoutubeID sets the "youtube_id" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateYoutubeID() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.UpdateYoutubeID()
	})
}

// ClearYoutubeID clears the value of the "youtube_id" field.
func (u *UserUpsertBulk) ClearYoutubeID() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.ClearYoutubeID()
	})
}

// SetYoutubeToken sets the "youtube_token" field.
func (u *UserUpsertBulk) SetYoutubeToken(v *oauth2.Token) *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.SetYoutubeToken(v)
	})
}

// UpdateYoutubeToken sets the "youtube_token" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateYoutubeToken() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.UpdateYoutubeToken()
	})
}

// ClearYoutubeToken clears the value of the "youtube_token" field.
func (u *UserUpsertBulk) ClearYoutubeToken() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.ClearYoutubeToken()
	})
}

// SetDiscordToken sets the "discord_token" field.
func (u *UserUpsertBulk) SetDiscordToken(v *oauth2.Token) *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.SetDiscordToken(v)
	})
}

// UpdateDiscordToken sets the "discord_token" field to the value that was provided on create.
func (u *UserUpsertBulk) UpdateDiscordToken() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.UpdateDiscordToken()
	})
}

// ClearDiscordToken clears the value of the "discord_token" field.
func (u *UserUpsertBulk) ClearDiscordToken() *UserUpsertBulk {
	return u.Update(func(s *UserUpsert) {
		s.ClearDiscordToken()
	})
}

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

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