// 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/guildrole"
	"github.com/member-gentei/member-gentei/gentei/ent/predicate"
	"github.com/member-gentei/member-gentei/gentei/ent/usermembership"
	"github.com/member-gentei/member-gentei/gentei/ent/youtubetalent"
)

// YouTubeTalentUpdate is the builder for updating YouTubeTalent entities.
type YouTubeTalentUpdate struct {
	config
	hooks    []Hook
	mutation *YouTubeTalentMutation
}

// Where appends a list predicates to the YouTubeTalentUpdate builder.
func (yttu *YouTubeTalentUpdate) Where(ps ...predicate.YouTubeTalent) *YouTubeTalentUpdate {
	yttu.mutation.Where(ps...)
	return yttu
}

// SetChannelName sets the "channel_name" field.
func (yttu *YouTubeTalentUpdate) SetChannelName(s string) *YouTubeTalentUpdate {
	yttu.mutation.SetChannelName(s)
	return yttu
}

// SetNillableChannelName sets the "channel_name" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableChannelName(s *string) *YouTubeTalentUpdate {
	if s != nil {
		yttu.SetChannelName(*s)
	}
	return yttu
}

// SetThumbnailURL sets the "thumbnail_url" field.
func (yttu *YouTubeTalentUpdate) SetThumbnailURL(s string) *YouTubeTalentUpdate {
	yttu.mutation.SetThumbnailURL(s)
	return yttu
}

// SetNillableThumbnailURL sets the "thumbnail_url" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableThumbnailURL(s *string) *YouTubeTalentUpdate {
	if s != nil {
		yttu.SetThumbnailURL(*s)
	}
	return yttu
}

// SetMembershipVideoID sets the "membership_video_id" field.
func (yttu *YouTubeTalentUpdate) SetMembershipVideoID(s string) *YouTubeTalentUpdate {
	yttu.mutation.SetMembershipVideoID(s)
	return yttu
}

// SetNillableMembershipVideoID sets the "membership_video_id" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableMembershipVideoID(s *string) *YouTubeTalentUpdate {
	if s != nil {
		yttu.SetMembershipVideoID(*s)
	}
	return yttu
}

// ClearMembershipVideoID clears the value of the "membership_video_id" field.
func (yttu *YouTubeTalentUpdate) ClearMembershipVideoID() *YouTubeTalentUpdate {
	yttu.mutation.ClearMembershipVideoID()
	return yttu
}

// SetLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field.
func (yttu *YouTubeTalentUpdate) SetLastMembershipVideoIDMiss(t time.Time) *YouTubeTalentUpdate {
	yttu.mutation.SetLastMembershipVideoIDMiss(t)
	return yttu
}

// SetNillableLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableLastMembershipVideoIDMiss(t *time.Time) *YouTubeTalentUpdate {
	if t != nil {
		yttu.SetLastMembershipVideoIDMiss(*t)
	}
	return yttu
}

// ClearLastMembershipVideoIDMiss clears the value of the "last_membership_video_id_miss" field.
func (yttu *YouTubeTalentUpdate) ClearLastMembershipVideoIDMiss() *YouTubeTalentUpdate {
	yttu.mutation.ClearLastMembershipVideoIDMiss()
	return yttu
}

// SetLastUpdated sets the "last_updated" field.
func (yttu *YouTubeTalentUpdate) SetLastUpdated(t time.Time) *YouTubeTalentUpdate {
	yttu.mutation.SetLastUpdated(t)
	return yttu
}

// SetNillableLastUpdated sets the "last_updated" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableLastUpdated(t *time.Time) *YouTubeTalentUpdate {
	if t != nil {
		yttu.SetLastUpdated(*t)
	}
	return yttu
}

// SetDisabled sets the "disabled" field.
func (yttu *YouTubeTalentUpdate) SetDisabled(t time.Time) *YouTubeTalentUpdate {
	yttu.mutation.SetDisabled(t)
	return yttu
}

// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableDisabled(t *time.Time) *YouTubeTalentUpdate {
	if t != nil {
		yttu.SetDisabled(*t)
	}
	return yttu
}

// ClearDisabled clears the value of the "disabled" field.
func (yttu *YouTubeTalentUpdate) ClearDisabled() *YouTubeTalentUpdate {
	yttu.mutation.ClearDisabled()
	return yttu
}

// SetDisabledPermanently sets the "disabled_permanently" field.
func (yttu *YouTubeTalentUpdate) SetDisabledPermanently(b bool) *YouTubeTalentUpdate {
	yttu.mutation.SetDisabledPermanently(b)
	return yttu
}

// SetNillableDisabledPermanently sets the "disabled_permanently" field if the given value is not nil.
func (yttu *YouTubeTalentUpdate) SetNillableDisabledPermanently(b *bool) *YouTubeTalentUpdate {
	if b != nil {
		yttu.SetDisabledPermanently(*b)
	}
	return yttu
}

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

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

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

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

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

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

// Mutation returns the YouTubeTalentMutation object of the builder.
func (yttu *YouTubeTalentUpdate) Mutation() *YouTubeTalentMutation {
	return yttu.mutation
}

// ClearGuilds clears all "guilds" edges to the Guild entity.
func (yttu *YouTubeTalentUpdate) ClearGuilds() *YouTubeTalentUpdate {
	yttu.mutation.ClearGuilds()
	return yttu
}

// RemoveGuildIDs removes the "guilds" edge to Guild entities by IDs.
func (yttu *YouTubeTalentUpdate) RemoveGuildIDs(ids ...uint64) *YouTubeTalentUpdate {
	yttu.mutation.RemoveGuildIDs(ids...)
	return yttu
}

// RemoveGuilds removes "guilds" edges to Guild entities.
func (yttu *YouTubeTalentUpdate) RemoveGuilds(g ...*Guild) *YouTubeTalentUpdate {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return yttu.RemoveGuildIDs(ids...)
}

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

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

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

// ClearMemberships clears all "memberships" edges to the UserMembership entity.
func (yttu *YouTubeTalentUpdate) ClearMemberships() *YouTubeTalentUpdate {
	yttu.mutation.ClearMemberships()
	return yttu
}

// RemoveMembershipIDs removes the "memberships" edge to UserMembership entities by IDs.
func (yttu *YouTubeTalentUpdate) RemoveMembershipIDs(ids ...int) *YouTubeTalentUpdate {
	yttu.mutation.RemoveMembershipIDs(ids...)
	return yttu
}

// RemoveMemberships removes "memberships" edges to UserMembership entities.
func (yttu *YouTubeTalentUpdate) RemoveMemberships(u ...*UserMembership) *YouTubeTalentUpdate {
	ids := make([]int, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return yttu.RemoveMembershipIDs(ids...)
}

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

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

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

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

func (yttu *YouTubeTalentUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(youtubetalent.Table, youtubetalent.Columns, sqlgraph.NewFieldSpec(youtubetalent.FieldID, field.TypeString))
	if ps := yttu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := yttu.mutation.ChannelName(); ok {
		_spec.SetField(youtubetalent.FieldChannelName, field.TypeString, value)
	}
	if value, ok := yttu.mutation.ThumbnailURL(); ok {
		_spec.SetField(youtubetalent.FieldThumbnailURL, field.TypeString, value)
	}
	if value, ok := yttu.mutation.MembershipVideoID(); ok {
		_spec.SetField(youtubetalent.FieldMembershipVideoID, field.TypeString, value)
	}
	if yttu.mutation.MembershipVideoIDCleared() {
		_spec.ClearField(youtubetalent.FieldMembershipVideoID, field.TypeString)
	}
	if value, ok := yttu.mutation.LastMembershipVideoIDMiss(); ok {
		_spec.SetField(youtubetalent.FieldLastMembershipVideoIDMiss, field.TypeTime, value)
	}
	if yttu.mutation.LastMembershipVideoIDMissCleared() {
		_spec.ClearField(youtubetalent.FieldLastMembershipVideoIDMiss, field.TypeTime)
	}
	if value, ok := yttu.mutation.LastUpdated(); ok {
		_spec.SetField(youtubetalent.FieldLastUpdated, field.TypeTime, value)
	}
	if value, ok := yttu.mutation.Disabled(); ok {
		_spec.SetField(youtubetalent.FieldDisabled, field.TypeTime, value)
	}
	if yttu.mutation.DisabledCleared() {
		_spec.ClearField(youtubetalent.FieldDisabled, field.TypeTime)
	}
	if value, ok := yttu.mutation.DisabledPermanently(); ok {
		_spec.SetField(youtubetalent.FieldDisabledPermanently, field.TypeBool, value)
	}
	if yttu.mutation.GuildsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   youtubetalent.GuildsTable,
			Columns: youtubetalent.GuildsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guild.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttu.mutation.RemovedGuildsIDs(); len(nodes) > 0 && !yttu.mutation.GuildsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   youtubetalent.GuildsTable,
			Columns: youtubetalent.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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttu.mutation.GuildsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   youtubetalent.GuildsTable,
			Columns: youtubetalent.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.Add = append(_spec.Edges.Add, edge)
	}
	if yttu.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   youtubetalent.RolesTable,
			Columns: []string{youtubetalent.RolesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guildrole.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttu.mutation.RemovedRolesIDs(); len(nodes) > 0 && !yttu.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   youtubetalent.RolesTable,
			Columns: []string{youtubetalent.RolesColumn},
			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 := yttu.mutation.RolesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   youtubetalent.RolesTable,
			Columns: []string{youtubetalent.RolesColumn},
			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 yttu.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   youtubetalent.MembershipsTable,
			Columns: []string{youtubetalent.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usermembership.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttu.mutation.RemovedMembershipsIDs(); len(nodes) > 0 && !yttu.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   youtubetalent.MembershipsTable,
			Columns: []string{youtubetalent.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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttu.mutation.MembershipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   youtubetalent.MembershipsTable,
			Columns: []string{youtubetalent.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.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, yttu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{youtubetalent.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	yttu.mutation.done = true
	return n, nil
}

// YouTubeTalentUpdateOne is the builder for updating a single YouTubeTalent entity.
type YouTubeTalentUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *YouTubeTalentMutation
}

// SetChannelName sets the "channel_name" field.
func (yttuo *YouTubeTalentUpdateOne) SetChannelName(s string) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetChannelName(s)
	return yttuo
}

// SetNillableChannelName sets the "channel_name" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableChannelName(s *string) *YouTubeTalentUpdateOne {
	if s != nil {
		yttuo.SetChannelName(*s)
	}
	return yttuo
}

// SetThumbnailURL sets the "thumbnail_url" field.
func (yttuo *YouTubeTalentUpdateOne) SetThumbnailURL(s string) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetThumbnailURL(s)
	return yttuo
}

// SetNillableThumbnailURL sets the "thumbnail_url" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableThumbnailURL(s *string) *YouTubeTalentUpdateOne {
	if s != nil {
		yttuo.SetThumbnailURL(*s)
	}
	return yttuo
}

// SetMembershipVideoID sets the "membership_video_id" field.
func (yttuo *YouTubeTalentUpdateOne) SetMembershipVideoID(s string) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetMembershipVideoID(s)
	return yttuo
}

// SetNillableMembershipVideoID sets the "membership_video_id" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableMembershipVideoID(s *string) *YouTubeTalentUpdateOne {
	if s != nil {
		yttuo.SetMembershipVideoID(*s)
	}
	return yttuo
}

// ClearMembershipVideoID clears the value of the "membership_video_id" field.
func (yttuo *YouTubeTalentUpdateOne) ClearMembershipVideoID() *YouTubeTalentUpdateOne {
	yttuo.mutation.ClearMembershipVideoID()
	return yttuo
}

// SetLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field.
func (yttuo *YouTubeTalentUpdateOne) SetLastMembershipVideoIDMiss(t time.Time) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetLastMembershipVideoIDMiss(t)
	return yttuo
}

// SetNillableLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableLastMembershipVideoIDMiss(t *time.Time) *YouTubeTalentUpdateOne {
	if t != nil {
		yttuo.SetLastMembershipVideoIDMiss(*t)
	}
	return yttuo
}

// ClearLastMembershipVideoIDMiss clears the value of the "last_membership_video_id_miss" field.
func (yttuo *YouTubeTalentUpdateOne) ClearLastMembershipVideoIDMiss() *YouTubeTalentUpdateOne {
	yttuo.mutation.ClearLastMembershipVideoIDMiss()
	return yttuo
}

// SetLastUpdated sets the "last_updated" field.
func (yttuo *YouTubeTalentUpdateOne) SetLastUpdated(t time.Time) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetLastUpdated(t)
	return yttuo
}

// SetNillableLastUpdated sets the "last_updated" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableLastUpdated(t *time.Time) *YouTubeTalentUpdateOne {
	if t != nil {
		yttuo.SetLastUpdated(*t)
	}
	return yttuo
}

// SetDisabled sets the "disabled" field.
func (yttuo *YouTubeTalentUpdateOne) SetDisabled(t time.Time) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetDisabled(t)
	return yttuo
}

// SetNillableDisabled sets the "disabled" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableDisabled(t *time.Time) *YouTubeTalentUpdateOne {
	if t != nil {
		yttuo.SetDisabled(*t)
	}
	return yttuo
}

// ClearDisabled clears the value of the "disabled" field.
func (yttuo *YouTubeTalentUpdateOne) ClearDisabled() *YouTubeTalentUpdateOne {
	yttuo.mutation.ClearDisabled()
	return yttuo
}

// SetDisabledPermanently sets the "disabled_permanently" field.
func (yttuo *YouTubeTalentUpdateOne) SetDisabledPermanently(b bool) *YouTubeTalentUpdateOne {
	yttuo.mutation.SetDisabledPermanently(b)
	return yttuo
}

// SetNillableDisabledPermanently sets the "disabled_permanently" field if the given value is not nil.
func (yttuo *YouTubeTalentUpdateOne) SetNillableDisabledPermanently(b *bool) *YouTubeTalentUpdateOne {
	if b != nil {
		yttuo.SetDisabledPermanently(*b)
	}
	return yttuo
}

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

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

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

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

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

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

// Mutation returns the YouTubeTalentMutation object of the builder.
func (yttuo *YouTubeTalentUpdateOne) Mutation() *YouTubeTalentMutation {
	return yttuo.mutation
}

// ClearGuilds clears all "guilds" edges to the Guild entity.
func (yttuo *YouTubeTalentUpdateOne) ClearGuilds() *YouTubeTalentUpdateOne {
	yttuo.mutation.ClearGuilds()
	return yttuo
}

// RemoveGuildIDs removes the "guilds" edge to Guild entities by IDs.
func (yttuo *YouTubeTalentUpdateOne) RemoveGuildIDs(ids ...uint64) *YouTubeTalentUpdateOne {
	yttuo.mutation.RemoveGuildIDs(ids...)
	return yttuo
}

// RemoveGuilds removes "guilds" edges to Guild entities.
func (yttuo *YouTubeTalentUpdateOne) RemoveGuilds(g ...*Guild) *YouTubeTalentUpdateOne {
	ids := make([]uint64, len(g))
	for i := range g {
		ids[i] = g[i].ID
	}
	return yttuo.RemoveGuildIDs(ids...)
}

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

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

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

// ClearMemberships clears all "memberships" edges to the UserMembership entity.
func (yttuo *YouTubeTalentUpdateOne) ClearMemberships() *YouTubeTalentUpdateOne {
	yttuo.mutation.ClearMemberships()
	return yttuo
}

// RemoveMembershipIDs removes the "memberships" edge to UserMembership entities by IDs.
func (yttuo *YouTubeTalentUpdateOne) RemoveMembershipIDs(ids ...int) *YouTubeTalentUpdateOne {
	yttuo.mutation.RemoveMembershipIDs(ids...)
	return yttuo
}

// RemoveMemberships removes "memberships" edges to UserMembership entities.
func (yttuo *YouTubeTalentUpdateOne) RemoveMemberships(u ...*UserMembership) *YouTubeTalentUpdateOne {
	ids := make([]int, len(u))
	for i := range u {
		ids[i] = u[i].ID
	}
	return yttuo.RemoveMembershipIDs(ids...)
}

// Where appends a list predicates to the YouTubeTalentUpdate builder.
func (yttuo *YouTubeTalentUpdateOne) Where(ps ...predicate.YouTubeTalent) *YouTubeTalentUpdateOne {
	yttuo.mutation.Where(ps...)
	return yttuo
}

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

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

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

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

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

func (yttuo *YouTubeTalentUpdateOne) sqlSave(ctx context.Context) (_node *YouTubeTalent, err error) {
	_spec := sqlgraph.NewUpdateSpec(youtubetalent.Table, youtubetalent.Columns, sqlgraph.NewFieldSpec(youtubetalent.FieldID, field.TypeString))
	id, ok := yttuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "YouTubeTalent.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := yttuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, youtubetalent.FieldID)
		for _, f := range fields {
			if !youtubetalent.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != youtubetalent.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := yttuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := yttuo.mutation.ChannelName(); ok {
		_spec.SetField(youtubetalent.FieldChannelName, field.TypeString, value)
	}
	if value, ok := yttuo.mutation.ThumbnailURL(); ok {
		_spec.SetField(youtubetalent.FieldThumbnailURL, field.TypeString, value)
	}
	if value, ok := yttuo.mutation.MembershipVideoID(); ok {
		_spec.SetField(youtubetalent.FieldMembershipVideoID, field.TypeString, value)
	}
	if yttuo.mutation.MembershipVideoIDCleared() {
		_spec.ClearField(youtubetalent.FieldMembershipVideoID, field.TypeString)
	}
	if value, ok := yttuo.mutation.LastMembershipVideoIDMiss(); ok {
		_spec.SetField(youtubetalent.FieldLastMembershipVideoIDMiss, field.TypeTime, value)
	}
	if yttuo.mutation.LastMembershipVideoIDMissCleared() {
		_spec.ClearField(youtubetalent.FieldLastMembershipVideoIDMiss, field.TypeTime)
	}
	if value, ok := yttuo.mutation.LastUpdated(); ok {
		_spec.SetField(youtubetalent.FieldLastUpdated, field.TypeTime, value)
	}
	if value, ok := yttuo.mutation.Disabled(); ok {
		_spec.SetField(youtubetalent.FieldDisabled, field.TypeTime, value)
	}
	if yttuo.mutation.DisabledCleared() {
		_spec.ClearField(youtubetalent.FieldDisabled, field.TypeTime)
	}
	if value, ok := yttuo.mutation.DisabledPermanently(); ok {
		_spec.SetField(youtubetalent.FieldDisabledPermanently, field.TypeBool, value)
	}
	if yttuo.mutation.GuildsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   youtubetalent.GuildsTable,
			Columns: youtubetalent.GuildsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guild.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttuo.mutation.RemovedGuildsIDs(); len(nodes) > 0 && !yttuo.mutation.GuildsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   youtubetalent.GuildsTable,
			Columns: youtubetalent.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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttuo.mutation.GuildsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   youtubetalent.GuildsTable,
			Columns: youtubetalent.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.Add = append(_spec.Edges.Add, edge)
	}
	if yttuo.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   youtubetalent.RolesTable,
			Columns: []string{youtubetalent.RolesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(guildrole.FieldID, field.TypeUint64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttuo.mutation.RemovedRolesIDs(); len(nodes) > 0 && !yttuo.mutation.RolesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   youtubetalent.RolesTable,
			Columns: []string{youtubetalent.RolesColumn},
			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 := yttuo.mutation.RolesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   youtubetalent.RolesTable,
			Columns: []string{youtubetalent.RolesColumn},
			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 yttuo.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   youtubetalent.MembershipsTable,
			Columns: []string{youtubetalent.MembershipsColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(usermembership.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttuo.mutation.RemovedMembershipsIDs(); len(nodes) > 0 && !yttuo.mutation.MembershipsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   youtubetalent.MembershipsTable,
			Columns: []string{youtubetalent.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.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := yttuo.mutation.MembershipsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   youtubetalent.MembershipsTable,
			Columns: []string{youtubetalent.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.Add = append(_spec.Edges.Add, edge)
	}
	_node = &YouTubeTalent{config: yttuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, yttuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{youtubetalent.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	yttuo.mutation.done = true
	return _node, nil
}
