// 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/predicate"
	"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"
)

// UserMembershipUpdate is the builder for updating UserMembership entities.
type UserMembershipUpdate struct {
	config
	hooks    []Hook
	mutation *UserMembershipMutation
}

// Where appends a list predicates to the UserMembershipUpdate builder.
func (umu *UserMembershipUpdate) Where(ps ...predicate.UserMembership) *UserMembershipUpdate {
	umu.mutation.Where(ps...)
	return umu
}

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

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

// ClearFirstFailed clears the value of the "first_failed" field.
func (umu *UserMembershipUpdate) ClearFirstFailed() *UserMembershipUpdate {
	umu.mutation.ClearFirstFailed()
	return umu
}

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

// SetNillableLastVerified sets the "last_verified" field if the given value is not nil.
func (umu *UserMembershipUpdate) SetNillableLastVerified(t *time.Time) *UserMembershipUpdate {
	if t != nil {
		umu.SetLastVerified(*t)
	}
	return umu
}

// SetFailCount sets the "fail_count" field.
func (umu *UserMembershipUpdate) SetFailCount(i int) *UserMembershipUpdate {
	umu.mutation.ResetFailCount()
	umu.mutation.SetFailCount(i)
	return umu
}

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

// AddFailCount adds i to the "fail_count" field.
func (umu *UserMembershipUpdate) AddFailCount(i int) *UserMembershipUpdate {
	umu.mutation.AddFailCount(i)
	return umu
}

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

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

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

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

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

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

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

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

// ClearUser clears the "user" edge to the User entity.
func (umu *UserMembershipUpdate) ClearUser() *UserMembershipUpdate {
	umu.mutation.ClearUser()
	return umu
}

// ClearYoutubeTalent clears the "youtube_talent" edge to the YouTubeTalent entity.
func (umu *UserMembershipUpdate) ClearYoutubeTalent() *UserMembershipUpdate {
	umu.mutation.ClearYoutubeTalent()
	return umu
}

// ClearRoles clears all "roles" edges to the GuildRole entity.
func (umu *UserMembershipUpdate) ClearRoles() *UserMembershipUpdate {
	umu.mutation.ClearRoles()
	return umu
}

// RemoveRoleIDs removes the "roles" edge to GuildRole entities by IDs.
func (umu *UserMembershipUpdate) RemoveRoleIDs(ids ...uint64) *UserMembershipUpdate {
	umu.mutation.RemoveRoleIDs(ids...)
	return umu
}

// RemoveRoles removes "roles" edges to GuildRole entities.
func (umu *UserMembershipUpdate) RemoveRoles(g ...*GuildRole) *UserMembershipUpdate {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return umu.RemoveRoleIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (umu *UserMembershipUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, umu.sqlSave, umu.mutation, umu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (umu *UserMembershipUpdate) SaveX(ctx context.Context) int {
	affected, err := umu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

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

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

// check runs all checks and user-defined validators on the builder.
func (umu *UserMembershipUpdate) check() error {
	if umu.mutation.YoutubeTalentCleared() && len(umu.mutation.YoutubeTalentIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UserMembership.youtube_talent"`)
	}
	return nil
}

func (umu *UserMembershipUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := umu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(usermembership.Table, usermembership.Columns, sqlgraph.NewFieldSpec(usermembership.FieldID, field.TypeInt))
	if ps := umu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := umu.mutation.FirstFailed(); ok {
		_spec.SetField(usermembership.FieldFirstFailed, field.TypeTime, value)
	}
	if umu.mutation.FirstFailedCleared() {
		_spec.ClearField(usermembership.FieldFirstFailed, field.TypeTime)
	}
	if value, ok := umu.mutation.LastVerified(); ok {
		_spec.SetField(usermembership.FieldLastVerified, field.TypeTime, value)
	}
	if value, ok := umu.mutation.FailCount(); ok {
		_spec.SetField(usermembership.FieldFailCount, field.TypeInt, value)
	}
	if value, ok := umu.mutation.AddedFailCount(); ok {
		_spec.AddField(usermembership.FieldFailCount, field.TypeInt, value)
	}
	if umu.mutation.UserCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umu.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if umu.mutation.YoutubeTalentCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umu.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if umu.mutation.RolesCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umu.mutation.RemovedRolesIDs(); len(nodes) > 0 && !umu.mutation.RolesCleared() {
		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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umu.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.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, umu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usermembership.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	umu.mutation.done = true
	return n, nil
}

// UserMembershipUpdateOne is the builder for updating a single UserMembership entity.
type UserMembershipUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *UserMembershipMutation
}

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

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

// ClearFirstFailed clears the value of the "first_failed" field.
func (umuo *UserMembershipUpdateOne) ClearFirstFailed() *UserMembershipUpdateOne {
	umuo.mutation.ClearFirstFailed()
	return umuo
}

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

// SetNillableLastVerified sets the "last_verified" field if the given value is not nil.
func (umuo *UserMembershipUpdateOne) SetNillableLastVerified(t *time.Time) *UserMembershipUpdateOne {
	if t != nil {
		umuo.SetLastVerified(*t)
	}
	return umuo
}

// SetFailCount sets the "fail_count" field.
func (umuo *UserMembershipUpdateOne) SetFailCount(i int) *UserMembershipUpdateOne {
	umuo.mutation.ResetFailCount()
	umuo.mutation.SetFailCount(i)
	return umuo
}

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

// AddFailCount adds i to the "fail_count" field.
func (umuo *UserMembershipUpdateOne) AddFailCount(i int) *UserMembershipUpdateOne {
	umuo.mutation.AddFailCount(i)
	return umuo
}

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

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

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

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

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

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

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

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

// ClearUser clears the "user" edge to the User entity.
func (umuo *UserMembershipUpdateOne) ClearUser() *UserMembershipUpdateOne {
	umuo.mutation.ClearUser()
	return umuo
}

// ClearYoutubeTalent clears the "youtube_talent" edge to the YouTubeTalent entity.
func (umuo *UserMembershipUpdateOne) ClearYoutubeTalent() *UserMembershipUpdateOne {
	umuo.mutation.ClearYoutubeTalent()
	return umuo
}

// ClearRoles clears all "roles" edges to the GuildRole entity.
func (umuo *UserMembershipUpdateOne) ClearRoles() *UserMembershipUpdateOne {
	umuo.mutation.ClearRoles()
	return umuo
}

// RemoveRoleIDs removes the "roles" edge to GuildRole entities by IDs.
func (umuo *UserMembershipUpdateOne) RemoveRoleIDs(ids ...uint64) *UserMembershipUpdateOne {
	umuo.mutation.RemoveRoleIDs(ids...)
	return umuo
}

// RemoveRoles removes "roles" edges to GuildRole entities.
func (umuo *UserMembershipUpdateOne) RemoveRoles(g ...*GuildRole) *UserMembershipUpdateOne {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return umuo.RemoveRoleIDs(ids...)
}

// Where appends a list predicates to the UserMembershipUpdate builder.
func (umuo *UserMembershipUpdateOne) Where(ps ...predicate.UserMembership) *UserMembershipUpdateOne {
	umuo.mutation.Where(ps...)
	return umuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (umuo *UserMembershipUpdateOne) Select(field string, fields ...string) *UserMembershipUpdateOne {
	umuo.fields = append([]string{field}, fields...)
	return umuo
}

// Save executes the query and returns the updated UserMembership entity.
func (umuo *UserMembershipUpdateOne) Save(ctx context.Context) (*UserMembership, error) {
	return withHooks(ctx, umuo.sqlSave, umuo.mutation, umuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (umuo *UserMembershipUpdateOne) SaveX(ctx context.Context) *UserMembership {
	node, err := umuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (umuo *UserMembershipUpdateOne) Exec(ctx context.Context) error {
	_, err := umuo.Save(ctx)
	return err
}

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

// check runs all checks and user-defined validators on the builder.
func (umuo *UserMembershipUpdateOne) check() error {
	if umuo.mutation.YoutubeTalentCleared() && len(umuo.mutation.YoutubeTalentIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "UserMembership.youtube_talent"`)
	}
	return nil
}

func (umuo *UserMembershipUpdateOne) sqlSave(ctx context.Context) (_node *UserMembership, err error) {
	if err := umuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(usermembership.Table, usermembership.Columns, sqlgraph.NewFieldSpec(usermembership.FieldID, field.TypeInt))
	id, ok := umuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "UserMembership.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := umuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, usermembership.FieldID)
		for _, f := range fields {
			if !usermembership.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != usermembership.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := umuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := umuo.mutation.FirstFailed(); ok {
		_spec.SetField(usermembership.FieldFirstFailed, field.TypeTime, value)
	}
	if umuo.mutation.FirstFailedCleared() {
		_spec.ClearField(usermembership.FieldFirstFailed, field.TypeTime)
	}
	if value, ok := umuo.mutation.LastVerified(); ok {
		_spec.SetField(usermembership.FieldLastVerified, field.TypeTime, value)
	}
	if value, ok := umuo.mutation.FailCount(); ok {
		_spec.SetField(usermembership.FieldFailCount, field.TypeInt, value)
	}
	if value, ok := umuo.mutation.AddedFailCount(); ok {
		_spec.AddField(usermembership.FieldFailCount, field.TypeInt, value)
	}
	if umuo.mutation.UserCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umuo.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if umuo.mutation.YoutubeTalentCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umuo.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)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if umuo.mutation.RolesCleared() {
		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),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umuo.mutation.RemovedRolesIDs(); len(nodes) > 0 && !umuo.mutation.RolesCleared() {
		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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := umuo.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.Add = append(_spec.Edges.Add, edge)
	}
	_node = &UserMembership{config: umuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, umuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{usermembership.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	umuo.mutation.done = true
	return _node, nil
}
