// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect"
	"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/usermembership"
	"github.com/member-gentei/member-gentei/gentei/ent/youtubetalent"
)

// YouTubeTalentCreate is the builder for creating a YouTubeTalent entity.
type YouTubeTalentCreate struct {
	config
	mutation *YouTubeTalentMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

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

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

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

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

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

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

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

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

// SetID sets the "id" field.
func (yttc *YouTubeTalentCreate) SetID(s string) *YouTubeTalentCreate {
	yttc.mutation.SetID(s)
	return yttc
}

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

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

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

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

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

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

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

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

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

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

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

// defaults sets the default values of the builder before save.
func (yttc *YouTubeTalentCreate) defaults() {
	if _, ok := yttc.mutation.LastUpdated(); !ok {
		v := youtubetalent.DefaultLastUpdated()
		yttc.mutation.SetLastUpdated(v)
	}
	if _, ok := yttc.mutation.DisabledPermanently(); !ok {
		v := youtubetalent.DefaultDisabledPermanently
		yttc.mutation.SetDisabledPermanently(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (yttc *YouTubeTalentCreate) check() error {
	if _, ok := yttc.mutation.ChannelName(); !ok {
		return &ValidationError{Name: "channel_name", err: errors.New(`ent: missing required field "YouTubeTalent.channel_name"`)}
	}
	if _, ok := yttc.mutation.ThumbnailURL(); !ok {
		return &ValidationError{Name: "thumbnail_url", err: errors.New(`ent: missing required field "YouTubeTalent.thumbnail_url"`)}
	}
	if _, ok := yttc.mutation.LastUpdated(); !ok {
		return &ValidationError{Name: "last_updated", err: errors.New(`ent: missing required field "YouTubeTalent.last_updated"`)}
	}
	if _, ok := yttc.mutation.DisabledPermanently(); !ok {
		return &ValidationError{Name: "disabled_permanently", err: errors.New(`ent: missing required field "YouTubeTalent.disabled_permanently"`)}
	}
	return nil
}

func (yttc *YouTubeTalentCreate) sqlSave(ctx context.Context) (*YouTubeTalent, error) {
	if err := yttc.check(); err != nil {
		return nil, err
	}
	_node, _spec := yttc.createSpec()
	if err := sqlgraph.CreateNode(ctx, yttc.driver, _spec); err != nil {
		if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	if _spec.ID.Value != nil {
		if id, ok := _spec.ID.Value.(string); ok {
			_node.ID = id
		} else {
			return nil, fmt.Errorf("unexpected YouTubeTalent.ID type: %T", _spec.ID.Value)
		}
	}
	yttc.mutation.id = &_node.ID
	yttc.mutation.done = true
	return _node, nil
}

func (yttc *YouTubeTalentCreate) createSpec() (*YouTubeTalent, *sqlgraph.CreateSpec) {
	var (
		_node = &YouTubeTalent{config: yttc.config}
		_spec = sqlgraph.NewCreateSpec(youtubetalent.Table, sqlgraph.NewFieldSpec(youtubetalent.FieldID, field.TypeString))
	)
	_spec.OnConflict = yttc.conflict
	if id, ok := yttc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = id
	}
	if value, ok := yttc.mutation.ChannelName(); ok {
		_spec.SetField(youtubetalent.FieldChannelName, field.TypeString, value)
		_node.ChannelName = value
	}
	if value, ok := yttc.mutation.ThumbnailURL(); ok {
		_spec.SetField(youtubetalent.FieldThumbnailURL, field.TypeString, value)
		_node.ThumbnailURL = value
	}
	if value, ok := yttc.mutation.MembershipVideoID(); ok {
		_spec.SetField(youtubetalent.FieldMembershipVideoID, field.TypeString, value)
		_node.MembershipVideoID = value
	}
	if value, ok := yttc.mutation.LastMembershipVideoIDMiss(); ok {
		_spec.SetField(youtubetalent.FieldLastMembershipVideoIDMiss, field.TypeTime, value)
		_node.LastMembershipVideoIDMiss = value
	}
	if value, ok := yttc.mutation.LastUpdated(); ok {
		_spec.SetField(youtubetalent.FieldLastUpdated, field.TypeTime, value)
		_node.LastUpdated = value
	}
	if value, ok := yttc.mutation.Disabled(); ok {
		_spec.SetField(youtubetalent.FieldDisabled, field.TypeTime, value)
		_node.Disabled = value
	}
	if value, ok := yttc.mutation.DisabledPermanently(); ok {
		_spec.SetField(youtubetalent.FieldDisabledPermanently, field.TypeBool, value)
		_node.DisabledPermanently = value
	}
	if nodes := yttc.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 = append(_spec.Edges, edge)
	}
	if nodes := yttc.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 = append(_spec.Edges, edge)
	}
	if nodes := yttc.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 = append(_spec.Edges, edge)
	}
	return _node, _spec
}

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.YouTubeTalent.Create().
//		SetChannelName(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.YouTubeTalentUpsert) {
//			SetChannelName(v+v).
//		}).
//		Exec(ctx)
func (yttc *YouTubeTalentCreate) OnConflict(opts ...sql.ConflictOption) *YouTubeTalentUpsertOne {
	yttc.conflict = opts
	return &YouTubeTalentUpsertOne{
		create: yttc,
	}
}

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

type (
	// YouTubeTalentUpsertOne is the builder for "upsert"-ing
	//  one YouTubeTalent node.
	YouTubeTalentUpsertOne struct {
		create *YouTubeTalentCreate
	}

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

// SetChannelName sets the "channel_name" field.
func (u *YouTubeTalentUpsert) SetChannelName(v string) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldChannelName, v)
	return u
}

// UpdateChannelName sets the "channel_name" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateChannelName() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldChannelName)
	return u
}

// SetThumbnailURL sets the "thumbnail_url" field.
func (u *YouTubeTalentUpsert) SetThumbnailURL(v string) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldThumbnailURL, v)
	return u
}

// UpdateThumbnailURL sets the "thumbnail_url" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateThumbnailURL() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldThumbnailURL)
	return u
}

// SetMembershipVideoID sets the "membership_video_id" field.
func (u *YouTubeTalentUpsert) SetMembershipVideoID(v string) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldMembershipVideoID, v)
	return u
}

// UpdateMembershipVideoID sets the "membership_video_id" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateMembershipVideoID() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldMembershipVideoID)
	return u
}

// ClearMembershipVideoID clears the value of the "membership_video_id" field.
func (u *YouTubeTalentUpsert) ClearMembershipVideoID() *YouTubeTalentUpsert {
	u.SetNull(youtubetalent.FieldMembershipVideoID)
	return u
}

// SetLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field.
func (u *YouTubeTalentUpsert) SetLastMembershipVideoIDMiss(v time.Time) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldLastMembershipVideoIDMiss, v)
	return u
}

// UpdateLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateLastMembershipVideoIDMiss() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldLastMembershipVideoIDMiss)
	return u
}

// ClearLastMembershipVideoIDMiss clears the value of the "last_membership_video_id_miss" field.
func (u *YouTubeTalentUpsert) ClearLastMembershipVideoIDMiss() *YouTubeTalentUpsert {
	u.SetNull(youtubetalent.FieldLastMembershipVideoIDMiss)
	return u
}

// SetLastUpdated sets the "last_updated" field.
func (u *YouTubeTalentUpsert) SetLastUpdated(v time.Time) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldLastUpdated, v)
	return u
}

// UpdateLastUpdated sets the "last_updated" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateLastUpdated() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldLastUpdated)
	return u
}

// SetDisabled sets the "disabled" field.
func (u *YouTubeTalentUpsert) SetDisabled(v time.Time) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldDisabled, v)
	return u
}

// UpdateDisabled sets the "disabled" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateDisabled() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldDisabled)
	return u
}

// ClearDisabled clears the value of the "disabled" field.
func (u *YouTubeTalentUpsert) ClearDisabled() *YouTubeTalentUpsert {
	u.SetNull(youtubetalent.FieldDisabled)
	return u
}

// SetDisabledPermanently sets the "disabled_permanently" field.
func (u *YouTubeTalentUpsert) SetDisabledPermanently(v bool) *YouTubeTalentUpsert {
	u.Set(youtubetalent.FieldDisabledPermanently, v)
	return u
}

// UpdateDisabledPermanently sets the "disabled_permanently" field to the value that was provided on create.
func (u *YouTubeTalentUpsert) UpdateDisabledPermanently() *YouTubeTalentUpsert {
	u.SetExcluded(youtubetalent.FieldDisabledPermanently)
	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.YouTubeTalent.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(youtubetalent.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *YouTubeTalentUpsertOne) UpdateNewValues() *YouTubeTalentUpsertOne {
	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(youtubetalent.FieldID)
		}
	}))
	return u
}

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

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

// SetChannelName sets the "channel_name" field.
func (u *YouTubeTalentUpsertOne) SetChannelName(v string) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetChannelName(v)
	})
}

// UpdateChannelName sets the "channel_name" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateChannelName() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateChannelName()
	})
}

// SetThumbnailURL sets the "thumbnail_url" field.
func (u *YouTubeTalentUpsertOne) SetThumbnailURL(v string) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetThumbnailURL(v)
	})
}

// UpdateThumbnailURL sets the "thumbnail_url" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateThumbnailURL() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateThumbnailURL()
	})
}

// SetMembershipVideoID sets the "membership_video_id" field.
func (u *YouTubeTalentUpsertOne) SetMembershipVideoID(v string) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetMembershipVideoID(v)
	})
}

// UpdateMembershipVideoID sets the "membership_video_id" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateMembershipVideoID() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateMembershipVideoID()
	})
}

// ClearMembershipVideoID clears the value of the "membership_video_id" field.
func (u *YouTubeTalentUpsertOne) ClearMembershipVideoID() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.ClearMembershipVideoID()
	})
}

// SetLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field.
func (u *YouTubeTalentUpsertOne) SetLastMembershipVideoIDMiss(v time.Time) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetLastMembershipVideoIDMiss(v)
	})
}

// UpdateLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateLastMembershipVideoIDMiss() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateLastMembershipVideoIDMiss()
	})
}

// ClearLastMembershipVideoIDMiss clears the value of the "last_membership_video_id_miss" field.
func (u *YouTubeTalentUpsertOne) ClearLastMembershipVideoIDMiss() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.ClearLastMembershipVideoIDMiss()
	})
}

// SetLastUpdated sets the "last_updated" field.
func (u *YouTubeTalentUpsertOne) SetLastUpdated(v time.Time) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetLastUpdated(v)
	})
}

// UpdateLastUpdated sets the "last_updated" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateLastUpdated() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateLastUpdated()
	})
}

// SetDisabled sets the "disabled" field.
func (u *YouTubeTalentUpsertOne) SetDisabled(v time.Time) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetDisabled(v)
	})
}

// UpdateDisabled sets the "disabled" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateDisabled() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateDisabled()
	})
}

// ClearDisabled clears the value of the "disabled" field.
func (u *YouTubeTalentUpsertOne) ClearDisabled() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.ClearDisabled()
	})
}

// SetDisabledPermanently sets the "disabled_permanently" field.
func (u *YouTubeTalentUpsertOne) SetDisabledPermanently(v bool) *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetDisabledPermanently(v)
	})
}

// UpdateDisabledPermanently sets the "disabled_permanently" field to the value that was provided on create.
func (u *YouTubeTalentUpsertOne) UpdateDisabledPermanently() *YouTubeTalentUpsertOne {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateDisabledPermanently()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *YouTubeTalentUpsertOne) 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 *YouTubeTalentUpsertOne) ID(ctx context.Context) (id string, err error) {
	if u.create.driver.Dialect() == dialect.MySQL {
		// In case of "ON CONFLICT", there is no way to get back non-numeric ID
		// fields from the database since MySQL does not support the RETURNING clause.
		return id, errors.New("ent: YouTubeTalentUpsertOne.ID is not supported by MySQL driver. Use YouTubeTalentUpsertOne.Exec instead")
	}
	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 *YouTubeTalentUpsertOne) IDX(ctx context.Context) string {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.YouTubeTalent.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.YouTubeTalentUpsert) {
//			SetChannelName(v+v).
//		}).
//		Exec(ctx)
func (yttcb *YouTubeTalentCreateBulk) OnConflict(opts ...sql.ConflictOption) *YouTubeTalentUpsertBulk {
	yttcb.conflict = opts
	return &YouTubeTalentUpsertBulk{
		create: yttcb,
	}
}

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

// YouTubeTalentUpsertBulk is the builder for "upsert"-ing
// a bulk of YouTubeTalent nodes.
type YouTubeTalentUpsertBulk struct {
	create *YouTubeTalentCreateBulk
}

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

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

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

// SetChannelName sets the "channel_name" field.
func (u *YouTubeTalentUpsertBulk) SetChannelName(v string) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetChannelName(v)
	})
}

// UpdateChannelName sets the "channel_name" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateChannelName() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateChannelName()
	})
}

// SetThumbnailURL sets the "thumbnail_url" field.
func (u *YouTubeTalentUpsertBulk) SetThumbnailURL(v string) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetThumbnailURL(v)
	})
}

// UpdateThumbnailURL sets the "thumbnail_url" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateThumbnailURL() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateThumbnailURL()
	})
}

// SetMembershipVideoID sets the "membership_video_id" field.
func (u *YouTubeTalentUpsertBulk) SetMembershipVideoID(v string) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetMembershipVideoID(v)
	})
}

// UpdateMembershipVideoID sets the "membership_video_id" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateMembershipVideoID() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateMembershipVideoID()
	})
}

// ClearMembershipVideoID clears the value of the "membership_video_id" field.
func (u *YouTubeTalentUpsertBulk) ClearMembershipVideoID() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.ClearMembershipVideoID()
	})
}

// SetLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field.
func (u *YouTubeTalentUpsertBulk) SetLastMembershipVideoIDMiss(v time.Time) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetLastMembershipVideoIDMiss(v)
	})
}

// UpdateLastMembershipVideoIDMiss sets the "last_membership_video_id_miss" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateLastMembershipVideoIDMiss() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateLastMembershipVideoIDMiss()
	})
}

// ClearLastMembershipVideoIDMiss clears the value of the "last_membership_video_id_miss" field.
func (u *YouTubeTalentUpsertBulk) ClearLastMembershipVideoIDMiss() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.ClearLastMembershipVideoIDMiss()
	})
}

// SetLastUpdated sets the "last_updated" field.
func (u *YouTubeTalentUpsertBulk) SetLastUpdated(v time.Time) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetLastUpdated(v)
	})
}

// UpdateLastUpdated sets the "last_updated" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateLastUpdated() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateLastUpdated()
	})
}

// SetDisabled sets the "disabled" field.
func (u *YouTubeTalentUpsertBulk) SetDisabled(v time.Time) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetDisabled(v)
	})
}

// UpdateDisabled sets the "disabled" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateDisabled() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateDisabled()
	})
}

// ClearDisabled clears the value of the "disabled" field.
func (u *YouTubeTalentUpsertBulk) ClearDisabled() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.ClearDisabled()
	})
}

// SetDisabledPermanently sets the "disabled_permanently" field.
func (u *YouTubeTalentUpsertBulk) SetDisabledPermanently(v bool) *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.SetDisabledPermanently(v)
	})
}

// UpdateDisabledPermanently sets the "disabled_permanently" field to the value that was provided on create.
func (u *YouTubeTalentUpsertBulk) UpdateDisabledPermanently() *YouTubeTalentUpsertBulk {
	return u.Update(func(s *YouTubeTalentUpsert) {
		s.UpdateDisabledPermanently()
	})
}

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

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