// 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/google/uuid"
	"github.com/lightsparkdev/spark/common/keys"
	"github.com/lightsparkdev/spark/so/ent/tokenoutput"
	"github.com/lightsparkdev/spark/so/ent/tokenpartialrevocationsecretshare"
)

// TokenPartialRevocationSecretShareCreate is the builder for creating a TokenPartialRevocationSecretShare entity.
type TokenPartialRevocationSecretShareCreate struct {
	config
	mutation *TokenPartialRevocationSecretShareMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetOperatorIdentityPublicKey sets the "operator_identity_public_key" field.
func (tprssc *TokenPartialRevocationSecretShareCreate) SetOperatorIdentityPublicKey(k keys.Public) *TokenPartialRevocationSecretShareCreate {
	tprssc.mutation.SetOperatorIdentityPublicKey(k)
	return tprssc
}

// SetSecretShare sets the "secret_share" field.
func (tprssc *TokenPartialRevocationSecretShareCreate) SetSecretShare(k keys.Private) *TokenPartialRevocationSecretShareCreate {
	tprssc.mutation.SetSecretShare(k)
	return tprssc
}

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

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

// SetTokenOutputID sets the "token_output" edge to the TokenOutput entity by ID.
func (tprssc *TokenPartialRevocationSecretShareCreate) SetTokenOutputID(id uuid.UUID) *TokenPartialRevocationSecretShareCreate {
	tprssc.mutation.SetTokenOutputID(id)
	return tprssc
}

// SetTokenOutput sets the "token_output" edge to the TokenOutput entity.
func (tprssc *TokenPartialRevocationSecretShareCreate) SetTokenOutput(t *TokenOutput) *TokenPartialRevocationSecretShareCreate {
	return tprssc.SetTokenOutputID(t.ID)
}

// Mutation returns the TokenPartialRevocationSecretShareMutation object of the builder.
func (tprssc *TokenPartialRevocationSecretShareCreate) Mutation() *TokenPartialRevocationSecretShareMutation {
	return tprssc.mutation
}

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

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

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

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

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

// check runs all checks and user-defined validators on the builder.
func (tprssc *TokenPartialRevocationSecretShareCreate) check() error {
	if _, ok := tprssc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "TokenPartialRevocationSecretShare.create_time"`)}
	}
	if _, ok := tprssc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "TokenPartialRevocationSecretShare.update_time"`)}
	}
	if _, ok := tprssc.mutation.OperatorIdentityPublicKey(); !ok {
		return &ValidationError{Name: "operator_identity_public_key", err: errors.New(`ent: missing required field "TokenPartialRevocationSecretShare.operator_identity_public_key"`)}
	}
	if _, ok := tprssc.mutation.SecretShare(); !ok {
		return &ValidationError{Name: "secret_share", err: errors.New(`ent: missing required field "TokenPartialRevocationSecretShare.secret_share"`)}
	}
	if len(tprssc.mutation.TokenOutputIDs()) == 0 {
		return &ValidationError{Name: "token_output", err: errors.New(`ent: missing required edge "TokenPartialRevocationSecretShare.token_output"`)}
	}
	return nil
}

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

func (tprssc *TokenPartialRevocationSecretShareCreate) createSpec() (*TokenPartialRevocationSecretShare, *sqlgraph.CreateSpec) {
	var (
		_node = &TokenPartialRevocationSecretShare{config: tprssc.config}
		_spec = sqlgraph.NewCreateSpec(tokenpartialrevocationsecretshare.Table, sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = tprssc.conflict
	if id, ok := tprssc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := tprssc.mutation.CreateTime(); ok {
		_spec.SetField(tokenpartialrevocationsecretshare.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := tprssc.mutation.UpdateTime(); ok {
		_spec.SetField(tokenpartialrevocationsecretshare.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := tprssc.mutation.OperatorIdentityPublicKey(); ok {
		_spec.SetField(tokenpartialrevocationsecretshare.FieldOperatorIdentityPublicKey, field.TypeBytes, value)
		_node.OperatorIdentityPublicKey = value
	}
	if value, ok := tprssc.mutation.SecretShare(); ok {
		_spec.SetField(tokenpartialrevocationsecretshare.FieldSecretShare, field.TypeBytes, value)
		_node.SecretShare = value
	}
	if nodes := tprssc.mutation.TokenOutputIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: true,
			Table:   tokenpartialrevocationsecretshare.TokenOutputTable,
			Columns: []string{tokenpartialrevocationsecretshare.TokenOutputColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenoutput.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.token_output_token_partial_revocation_secret_shares = &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.TokenPartialRevocationSecretShare.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.TokenPartialRevocationSecretShareUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (tprssc *TokenPartialRevocationSecretShareCreate) OnConflict(opts ...sql.ConflictOption) *TokenPartialRevocationSecretShareUpsertOne {
	tprssc.conflict = opts
	return &TokenPartialRevocationSecretShareUpsertOne{
		create: tprssc,
	}
}

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

type (
	// TokenPartialRevocationSecretShareUpsertOne is the builder for "upsert"-ing
	//  one TokenPartialRevocationSecretShare node.
	TokenPartialRevocationSecretShareUpsertOne struct {
		create *TokenPartialRevocationSecretShareCreate
	}

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

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

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

// SetOperatorIdentityPublicKey sets the "operator_identity_public_key" field.
func (u *TokenPartialRevocationSecretShareUpsert) SetOperatorIdentityPublicKey(v keys.Public) *TokenPartialRevocationSecretShareUpsert {
	u.Set(tokenpartialrevocationsecretshare.FieldOperatorIdentityPublicKey, v)
	return u
}

// UpdateOperatorIdentityPublicKey sets the "operator_identity_public_key" field to the value that was provided on create.
func (u *TokenPartialRevocationSecretShareUpsert) UpdateOperatorIdentityPublicKey() *TokenPartialRevocationSecretShareUpsert {
	u.SetExcluded(tokenpartialrevocationsecretshare.FieldOperatorIdentityPublicKey)
	return u
}

// SetSecretShare sets the "secret_share" field.
func (u *TokenPartialRevocationSecretShareUpsert) SetSecretShare(v keys.Private) *TokenPartialRevocationSecretShareUpsert {
	u.Set(tokenpartialrevocationsecretshare.FieldSecretShare, v)
	return u
}

// UpdateSecretShare sets the "secret_share" field to the value that was provided on create.
func (u *TokenPartialRevocationSecretShareUpsert) UpdateSecretShare() *TokenPartialRevocationSecretShareUpsert {
	u.SetExcluded(tokenpartialrevocationsecretshare.FieldSecretShare)
	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.TokenPartialRevocationSecretShare.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(tokenpartialrevocationsecretshare.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *TokenPartialRevocationSecretShareUpsertOne) UpdateNewValues() *TokenPartialRevocationSecretShareUpsertOne {
	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(tokenpartialrevocationsecretshare.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(tokenpartialrevocationsecretshare.FieldCreateTime)
		}
	}))
	return u
}

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

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

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

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

// SetOperatorIdentityPublicKey sets the "operator_identity_public_key" field.
func (u *TokenPartialRevocationSecretShareUpsertOne) SetOperatorIdentityPublicKey(v keys.Public) *TokenPartialRevocationSecretShareUpsertOne {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.SetOperatorIdentityPublicKey(v)
	})
}

// UpdateOperatorIdentityPublicKey sets the "operator_identity_public_key" field to the value that was provided on create.
func (u *TokenPartialRevocationSecretShareUpsertOne) UpdateOperatorIdentityPublicKey() *TokenPartialRevocationSecretShareUpsertOne {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.UpdateOperatorIdentityPublicKey()
	})
}

// SetSecretShare sets the "secret_share" field.
func (u *TokenPartialRevocationSecretShareUpsertOne) SetSecretShare(v keys.Private) *TokenPartialRevocationSecretShareUpsertOne {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.SetSecretShare(v)
	})
}

// UpdateSecretShare sets the "secret_share" field to the value that was provided on create.
func (u *TokenPartialRevocationSecretShareUpsertOne) UpdateSecretShare() *TokenPartialRevocationSecretShareUpsertOne {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.UpdateSecretShare()
	})
}

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

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

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

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

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

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

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

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

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

// TokenPartialRevocationSecretShareUpsertBulk is the builder for "upsert"-ing
// a bulk of TokenPartialRevocationSecretShare nodes.
type TokenPartialRevocationSecretShareUpsertBulk struct {
	create *TokenPartialRevocationSecretShareCreateBulk
}

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

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

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

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

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

// SetOperatorIdentityPublicKey sets the "operator_identity_public_key" field.
func (u *TokenPartialRevocationSecretShareUpsertBulk) SetOperatorIdentityPublicKey(v keys.Public) *TokenPartialRevocationSecretShareUpsertBulk {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.SetOperatorIdentityPublicKey(v)
	})
}

// UpdateOperatorIdentityPublicKey sets the "operator_identity_public_key" field to the value that was provided on create.
func (u *TokenPartialRevocationSecretShareUpsertBulk) UpdateOperatorIdentityPublicKey() *TokenPartialRevocationSecretShareUpsertBulk {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.UpdateOperatorIdentityPublicKey()
	})
}

// SetSecretShare sets the "secret_share" field.
func (u *TokenPartialRevocationSecretShareUpsertBulk) SetSecretShare(v keys.Private) *TokenPartialRevocationSecretShareUpsertBulk {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.SetSecretShare(v)
	})
}

// UpdateSecretShare sets the "secret_share" field to the value that was provided on create.
func (u *TokenPartialRevocationSecretShareUpsertBulk) UpdateSecretShare() *TokenPartialRevocationSecretShareUpsertBulk {
	return u.Update(func(s *TokenPartialRevocationSecretShareUpsert) {
		s.UpdateSecretShare()
	})
}

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

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