// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"registry-backend/ent/personalaccesstoken"
	"registry-backend/ent/publisher"
	"time"

	"entgo.io/ent/dialect"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
)

// PersonalAccessTokenCreate is the builder for creating a PersonalAccessToken entity.
type PersonalAccessTokenCreate struct {
	config
	mutation *PersonalAccessTokenMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

// SetCreateTime sets the "create_time" field.
func (patc *PersonalAccessTokenCreate) SetCreateTime(t time.Time) *PersonalAccessTokenCreate {
	patc.mutation.SetCreateTime(t)
	return patc
}

// SetNillableCreateTime sets the "create_time" field if the given value is not nil.
func (patc *PersonalAccessTokenCreate) SetNillableCreateTime(t *time.Time) *PersonalAccessTokenCreate {
	if t != nil {
		patc.SetCreateTime(*t)
	}
	return patc
}

// SetUpdateTime sets the "update_time" field.
func (patc *PersonalAccessTokenCreate) SetUpdateTime(t time.Time) *PersonalAccessTokenCreate {
	patc.mutation.SetUpdateTime(t)
	return patc
}

// SetNillableUpdateTime sets the "update_time" field if the given value is not nil.
func (patc *PersonalAccessTokenCreate) SetNillableUpdateTime(t *time.Time) *PersonalAccessTokenCreate {
	if t != nil {
		patc.SetUpdateTime(*t)
	}
	return patc
}

// SetName sets the "name" field.
func (patc *PersonalAccessTokenCreate) SetName(s string) *PersonalAccessTokenCreate {
	patc.mutation.SetName(s)
	return patc
}

// SetDescription sets the "description" field.
func (patc *PersonalAccessTokenCreate) SetDescription(s string) *PersonalAccessTokenCreate {
	patc.mutation.SetDescription(s)
	return patc
}

// SetPublisherID sets the "publisher_id" field.
func (patc *PersonalAccessTokenCreate) SetPublisherID(s string) *PersonalAccessTokenCreate {
	patc.mutation.SetPublisherID(s)
	return patc
}

// SetToken sets the "token" field.
func (patc *PersonalAccessTokenCreate) SetToken(s string) *PersonalAccessTokenCreate {
	patc.mutation.SetToken(s)
	return patc
}

// SetID sets the "id" field.
func (patc *PersonalAccessTokenCreate) SetID(u uuid.UUID) *PersonalAccessTokenCreate {
	patc.mutation.SetID(u)
	return patc
}

// SetNillableID sets the "id" field if the given value is not nil.
func (patc *PersonalAccessTokenCreate) SetNillableID(u *uuid.UUID) *PersonalAccessTokenCreate {
	if u != nil {
		patc.SetID(*u)
	}
	return patc
}

// SetPublisher sets the "publisher" edge to the Publisher entity.
func (patc *PersonalAccessTokenCreate) SetPublisher(p *Publisher) *PersonalAccessTokenCreate {
	return patc.SetPublisherID(p.ID)
}

// Mutation returns the PersonalAccessTokenMutation object of the builder.
func (patc *PersonalAccessTokenCreate) Mutation() *PersonalAccessTokenMutation {
	return patc.mutation
}

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

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

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

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

// defaults sets the default values of the builder before save.
func (patc *PersonalAccessTokenCreate) defaults() {
	if _, ok := patc.mutation.CreateTime(); !ok {
		v := personalaccesstoken.DefaultCreateTime()
		patc.mutation.SetCreateTime(v)
	}
	if _, ok := patc.mutation.UpdateTime(); !ok {
		v := personalaccesstoken.DefaultUpdateTime()
		patc.mutation.SetUpdateTime(v)
	}
	if _, ok := patc.mutation.ID(); !ok {
		v := personalaccesstoken.DefaultID()
		patc.mutation.SetID(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (patc *PersonalAccessTokenCreate) check() error {
	if _, ok := patc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "PersonalAccessToken.create_time"`)}
	}
	if _, ok := patc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "PersonalAccessToken.update_time"`)}
	}
	if _, ok := patc.mutation.Name(); !ok {
		return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "PersonalAccessToken.name"`)}
	}
	if _, ok := patc.mutation.Description(); !ok {
		return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "PersonalAccessToken.description"`)}
	}
	if _, ok := patc.mutation.PublisherID(); !ok {
		return &ValidationError{Name: "publisher_id", err: errors.New(`ent: missing required field "PersonalAccessToken.publisher_id"`)}
	}
	if _, ok := patc.mutation.Token(); !ok {
		return &ValidationError{Name: "token", err: errors.New(`ent: missing required field "PersonalAccessToken.token"`)}
	}
	if _, ok := patc.mutation.PublisherID(); !ok {
		return &ValidationError{Name: "publisher", err: errors.New(`ent: missing required edge "PersonalAccessToken.publisher"`)}
	}
	return nil
}

func (patc *PersonalAccessTokenCreate) sqlSave(ctx context.Context) (*PersonalAccessToken, error) {
	if err := patc.check(); err != nil {
		return nil, err
	}
	_node, _spec := patc.createSpec()
	if err := sqlgraph.CreateNode(ctx, patc.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.(*uuid.UUID); ok {
			_node.ID = *id
		} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
			return nil, err
		}
	}
	patc.mutation.id = &_node.ID
	patc.mutation.done = true
	return _node, nil
}

func (patc *PersonalAccessTokenCreate) createSpec() (*PersonalAccessToken, *sqlgraph.CreateSpec) {
	var (
		_node = &PersonalAccessToken{config: patc.config}
		_spec = sqlgraph.NewCreateSpec(personalaccesstoken.Table, sqlgraph.NewFieldSpec(personalaccesstoken.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = patc.conflict
	if id, ok := patc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := patc.mutation.CreateTime(); ok {
		_spec.SetField(personalaccesstoken.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := patc.mutation.UpdateTime(); ok {
		_spec.SetField(personalaccesstoken.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := patc.mutation.Name(); ok {
		_spec.SetField(personalaccesstoken.FieldName, field.TypeString, value)
		_node.Name = value
	}
	if value, ok := patc.mutation.Description(); ok {
		_spec.SetField(personalaccesstoken.FieldDescription, field.TypeString, value)
		_node.Description = value
	}
	if value, ok := patc.mutation.Token(); ok {
		_spec.SetField(personalaccesstoken.FieldToken, field.TypeString, value)
		_node.Token = value
	}
	if nodes := patc.mutation.PublisherIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   personalaccesstoken.PublisherTable,
			Columns: []string{personalaccesstoken.PublisherColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(publisher.FieldID, field.TypeString),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.PublisherID = nodes[0]
		_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.PersonalAccessToken.Create().
//		SetCreateTime(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.PersonalAccessTokenUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (patc *PersonalAccessTokenCreate) OnConflict(opts ...sql.ConflictOption) *PersonalAccessTokenUpsertOne {
	patc.conflict = opts
	return &PersonalAccessTokenUpsertOne{
		create: patc,
	}
}

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

type (
	// PersonalAccessTokenUpsertOne is the builder for "upsert"-ing
	//  one PersonalAccessToken node.
	PersonalAccessTokenUpsertOne struct {
		create *PersonalAccessTokenCreate
	}

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

// SetUpdateTime sets the "update_time" field.
func (u *PersonalAccessTokenUpsert) SetUpdateTime(v time.Time) *PersonalAccessTokenUpsert {
	u.Set(personalaccesstoken.FieldUpdateTime, v)
	return u
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsert) UpdateUpdateTime() *PersonalAccessTokenUpsert {
	u.SetExcluded(personalaccesstoken.FieldUpdateTime)
	return u
}

// SetName sets the "name" field.
func (u *PersonalAccessTokenUpsert) SetName(v string) *PersonalAccessTokenUpsert {
	u.Set(personalaccesstoken.FieldName, v)
	return u
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsert) UpdateName() *PersonalAccessTokenUpsert {
	u.SetExcluded(personalaccesstoken.FieldName)
	return u
}

// SetDescription sets the "description" field.
func (u *PersonalAccessTokenUpsert) SetDescription(v string) *PersonalAccessTokenUpsert {
	u.Set(personalaccesstoken.FieldDescription, v)
	return u
}

// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsert) UpdateDescription() *PersonalAccessTokenUpsert {
	u.SetExcluded(personalaccesstoken.FieldDescription)
	return u
}

// SetPublisherID sets the "publisher_id" field.
func (u *PersonalAccessTokenUpsert) SetPublisherID(v string) *PersonalAccessTokenUpsert {
	u.Set(personalaccesstoken.FieldPublisherID, v)
	return u
}

// UpdatePublisherID sets the "publisher_id" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsert) UpdatePublisherID() *PersonalAccessTokenUpsert {
	u.SetExcluded(personalaccesstoken.FieldPublisherID)
	return u
}

// SetToken sets the "token" field.
func (u *PersonalAccessTokenUpsert) SetToken(v string) *PersonalAccessTokenUpsert {
	u.Set(personalaccesstoken.FieldToken, v)
	return u
}

// UpdateToken sets the "token" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsert) UpdateToken() *PersonalAccessTokenUpsert {
	u.SetExcluded(personalaccesstoken.FieldToken)
	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.PersonalAccessToken.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(personalaccesstoken.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *PersonalAccessTokenUpsertOne) UpdateNewValues() *PersonalAccessTokenUpsertOne {
	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(personalaccesstoken.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(personalaccesstoken.FieldCreateTime)
		}
	}))
	return u
}

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

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

// SetUpdateTime sets the "update_time" field.
func (u *PersonalAccessTokenUpsertOne) SetUpdateTime(v time.Time) *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetUpdateTime(v)
	})
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertOne) UpdateUpdateTime() *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateUpdateTime()
	})
}

// SetName sets the "name" field.
func (u *PersonalAccessTokenUpsertOne) SetName(v string) *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertOne) UpdateName() *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateName()
	})
}

// SetDescription sets the "description" field.
func (u *PersonalAccessTokenUpsertOne) SetDescription(v string) *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetDescription(v)
	})
}

// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertOne) UpdateDescription() *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateDescription()
	})
}

// SetPublisherID sets the "publisher_id" field.
func (u *PersonalAccessTokenUpsertOne) SetPublisherID(v string) *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetPublisherID(v)
	})
}

// UpdatePublisherID sets the "publisher_id" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertOne) UpdatePublisherID() *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdatePublisherID()
	})
}

// SetToken sets the "token" field.
func (u *PersonalAccessTokenUpsertOne) SetToken(v string) *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetToken(v)
	})
}

// UpdateToken sets the "token" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertOne) UpdateToken() *PersonalAccessTokenUpsertOne {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateToken()
	})
}

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

// ExecX is like Exec, but panics if an error occurs.
func (u *PersonalAccessTokenUpsertOne) 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 *PersonalAccessTokenUpsertOne) ID(ctx context.Context) (id uuid.UUID, 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: PersonalAccessTokenUpsertOne.ID is not supported by MySQL driver. Use PersonalAccessTokenUpsertOne.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 *PersonalAccessTokenUpsertOne) IDX(ctx context.Context) uuid.UUID {
	id, err := u.ID(ctx)
	if err != nil {
		panic(err)
	}
	return id
}

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

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

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

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

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

// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
//	client.PersonalAccessToken.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.PersonalAccessTokenUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (patcb *PersonalAccessTokenCreateBulk) OnConflict(opts ...sql.ConflictOption) *PersonalAccessTokenUpsertBulk {
	patcb.conflict = opts
	return &PersonalAccessTokenUpsertBulk{
		create: patcb,
	}
}

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

// PersonalAccessTokenUpsertBulk is the builder for "upsert"-ing
// a bulk of PersonalAccessToken nodes.
type PersonalAccessTokenUpsertBulk struct {
	create *PersonalAccessTokenCreateBulk
}

// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
//	client.PersonalAccessToken.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(personalaccesstoken.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *PersonalAccessTokenUpsertBulk) UpdateNewValues() *PersonalAccessTokenUpsertBulk {
	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(personalaccesstoken.FieldID)
			}
			if _, exists := b.mutation.CreateTime(); exists {
				s.SetIgnore(personalaccesstoken.FieldCreateTime)
			}
		}
	}))
	return u
}

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

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

// SetUpdateTime sets the "update_time" field.
func (u *PersonalAccessTokenUpsertBulk) SetUpdateTime(v time.Time) *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetUpdateTime(v)
	})
}

// UpdateUpdateTime sets the "update_time" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertBulk) UpdateUpdateTime() *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateUpdateTime()
	})
}

// SetName sets the "name" field.
func (u *PersonalAccessTokenUpsertBulk) SetName(v string) *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetName(v)
	})
}

// UpdateName sets the "name" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertBulk) UpdateName() *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateName()
	})
}

// SetDescription sets the "description" field.
func (u *PersonalAccessTokenUpsertBulk) SetDescription(v string) *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetDescription(v)
	})
}

// UpdateDescription sets the "description" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertBulk) UpdateDescription() *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateDescription()
	})
}

// SetPublisherID sets the "publisher_id" field.
func (u *PersonalAccessTokenUpsertBulk) SetPublisherID(v string) *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetPublisherID(v)
	})
}

// UpdatePublisherID sets the "publisher_id" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertBulk) UpdatePublisherID() *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdatePublisherID()
	})
}

// SetToken sets the "token" field.
func (u *PersonalAccessTokenUpsertBulk) SetToken(v string) *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.SetToken(v)
	})
}

// UpdateToken sets the "token" field to the value that was provided on create.
func (u *PersonalAccessTokenUpsertBulk) UpdateToken() *PersonalAccessTokenUpsertBulk {
	return u.Update(func(s *PersonalAccessTokenUpsert) {
		s.UpdateToken()
	})
}

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

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