// 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/paymentintent"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
	"github.com/lightsparkdev/spark/so/ent/sparkinvoice"
	"github.com/lightsparkdev/spark/so/ent/tokencreate"
	"github.com/lightsparkdev/spark/so/ent/tokenmint"
	"github.com/lightsparkdev/spark/so/ent/tokenoutput"
	"github.com/lightsparkdev/spark/so/ent/tokentransaction"
	"github.com/lightsparkdev/spark/so/ent/tokentransactionpeersignature"
)

// TokenTransactionCreate is the builder for creating a TokenTransaction entity.
type TokenTransactionCreate struct {
	config
	mutation *TokenTransactionMutation
	hooks    []Hook
	conflict []sql.ConflictOption
}

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

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

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

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

// SetPartialTokenTransactionHash sets the "partial_token_transaction_hash" field.
func (ttc *TokenTransactionCreate) SetPartialTokenTransactionHash(b []byte) *TokenTransactionCreate {
	ttc.mutation.SetPartialTokenTransactionHash(b)
	return ttc
}

// SetFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field.
func (ttc *TokenTransactionCreate) SetFinalizedTokenTransactionHash(b []byte) *TokenTransactionCreate {
	ttc.mutation.SetFinalizedTokenTransactionHash(b)
	return ttc
}

// SetOperatorSignature sets the "operator_signature" field.
func (ttc *TokenTransactionCreate) SetOperatorSignature(b []byte) *TokenTransactionCreate {
	ttc.mutation.SetOperatorSignature(b)
	return ttc
}

// SetStatus sets the "status" field.
func (ttc *TokenTransactionCreate) SetStatus(sts schematype.TokenTransactionStatus) *TokenTransactionCreate {
	ttc.mutation.SetStatus(sts)
	return ttc
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableStatus(sts *schematype.TokenTransactionStatus) *TokenTransactionCreate {
	if sts != nil {
		ttc.SetStatus(*sts)
	}
	return ttc
}

// SetExpiryTime sets the "expiry_time" field.
func (ttc *TokenTransactionCreate) SetExpiryTime(t time.Time) *TokenTransactionCreate {
	ttc.mutation.SetExpiryTime(t)
	return ttc
}

// SetNillableExpiryTime sets the "expiry_time" field if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableExpiryTime(t *time.Time) *TokenTransactionCreate {
	if t != nil {
		ttc.SetExpiryTime(*t)
	}
	return ttc
}

// SetCoordinatorPublicKey sets the "coordinator_public_key" field.
func (ttc *TokenTransactionCreate) SetCoordinatorPublicKey(k keys.Public) *TokenTransactionCreate {
	ttc.mutation.SetCoordinatorPublicKey(k)
	return ttc
}

// SetNillableCoordinatorPublicKey sets the "coordinator_public_key" field if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableCoordinatorPublicKey(k *keys.Public) *TokenTransactionCreate {
	if k != nil {
		ttc.SetCoordinatorPublicKey(*k)
	}
	return ttc
}

// SetClientCreatedTimestamp sets the "client_created_timestamp" field.
func (ttc *TokenTransactionCreate) SetClientCreatedTimestamp(t time.Time) *TokenTransactionCreate {
	ttc.mutation.SetClientCreatedTimestamp(t)
	return ttc
}

// SetNillableClientCreatedTimestamp sets the "client_created_timestamp" field if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableClientCreatedTimestamp(t *time.Time) *TokenTransactionCreate {
	if t != nil {
		ttc.SetClientCreatedTimestamp(*t)
	}
	return ttc
}

// SetVersion sets the "version" field.
func (ttc *TokenTransactionCreate) SetVersion(stv schematype.TokenTransactionVersion) *TokenTransactionCreate {
	ttc.mutation.SetVersion(stv)
	return ttc
}

// SetNillableVersion sets the "version" field if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableVersion(stv *schematype.TokenTransactionVersion) *TokenTransactionCreate {
	if stv != nil {
		ttc.SetVersion(*stv)
	}
	return ttc
}

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

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

// AddSpentOutputIDs adds the "spent_output" edge to the TokenOutput entity by IDs.
func (ttc *TokenTransactionCreate) AddSpentOutputIDs(ids ...uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.AddSpentOutputIDs(ids...)
	return ttc
}

// AddSpentOutput adds the "spent_output" edges to the TokenOutput entity.
func (ttc *TokenTransactionCreate) AddSpentOutput(t ...*TokenOutput) *TokenTransactionCreate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return ttc.AddSpentOutputIDs(ids...)
}

// AddSpentOutputV2IDs adds the "spent_output_v2" edge to the TokenOutput entity by IDs.
func (ttc *TokenTransactionCreate) AddSpentOutputV2IDs(ids ...uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.AddSpentOutputV2IDs(ids...)
	return ttc
}

// AddSpentOutputV2 adds the "spent_output_v2" edges to the TokenOutput entity.
func (ttc *TokenTransactionCreate) AddSpentOutputV2(t ...*TokenOutput) *TokenTransactionCreate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return ttc.AddSpentOutputV2IDs(ids...)
}

// AddCreatedOutputIDs adds the "created_output" edge to the TokenOutput entity by IDs.
func (ttc *TokenTransactionCreate) AddCreatedOutputIDs(ids ...uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.AddCreatedOutputIDs(ids...)
	return ttc
}

// AddCreatedOutput adds the "created_output" edges to the TokenOutput entity.
func (ttc *TokenTransactionCreate) AddCreatedOutput(t ...*TokenOutput) *TokenTransactionCreate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return ttc.AddCreatedOutputIDs(ids...)
}

// SetMintID sets the "mint" edge to the TokenMint entity by ID.
func (ttc *TokenTransactionCreate) SetMintID(id uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.SetMintID(id)
	return ttc
}

// SetNillableMintID sets the "mint" edge to the TokenMint entity by ID if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableMintID(id *uuid.UUID) *TokenTransactionCreate {
	if id != nil {
		ttc = ttc.SetMintID(*id)
	}
	return ttc
}

// SetMint sets the "mint" edge to the TokenMint entity.
func (ttc *TokenTransactionCreate) SetMint(t *TokenMint) *TokenTransactionCreate {
	return ttc.SetMintID(t.ID)
}

// SetCreateID sets the "create" edge to the TokenCreate entity by ID.
func (ttc *TokenTransactionCreate) SetCreateID(id uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.SetCreateID(id)
	return ttc
}

// SetNillableCreateID sets the "create" edge to the TokenCreate entity by ID if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillableCreateID(id *uuid.UUID) *TokenTransactionCreate {
	if id != nil {
		ttc = ttc.SetCreateID(*id)
	}
	return ttc
}

// SetCreate sets the "create" edge to the TokenCreate entity.
func (ttc *TokenTransactionCreate) SetCreate(t *TokenCreate) *TokenTransactionCreate {
	return ttc.SetCreateID(t.ID)
}

// SetPaymentIntentID sets the "payment_intent" edge to the PaymentIntent entity by ID.
func (ttc *TokenTransactionCreate) SetPaymentIntentID(id uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.SetPaymentIntentID(id)
	return ttc
}

// SetNillablePaymentIntentID sets the "payment_intent" edge to the PaymentIntent entity by ID if the given value is not nil.
func (ttc *TokenTransactionCreate) SetNillablePaymentIntentID(id *uuid.UUID) *TokenTransactionCreate {
	if id != nil {
		ttc = ttc.SetPaymentIntentID(*id)
	}
	return ttc
}

// SetPaymentIntent sets the "payment_intent" edge to the PaymentIntent entity.
func (ttc *TokenTransactionCreate) SetPaymentIntent(p *PaymentIntent) *TokenTransactionCreate {
	return ttc.SetPaymentIntentID(p.ID)
}

// AddPeerSignatureIDs adds the "peer_signatures" edge to the TokenTransactionPeerSignature entity by IDs.
func (ttc *TokenTransactionCreate) AddPeerSignatureIDs(ids ...uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.AddPeerSignatureIDs(ids...)
	return ttc
}

// AddPeerSignatures adds the "peer_signatures" edges to the TokenTransactionPeerSignature entity.
func (ttc *TokenTransactionCreate) AddPeerSignatures(t ...*TokenTransactionPeerSignature) *TokenTransactionCreate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return ttc.AddPeerSignatureIDs(ids...)
}

// AddSparkInvoiceIDs adds the "spark_invoice" edge to the SparkInvoice entity by IDs.
func (ttc *TokenTransactionCreate) AddSparkInvoiceIDs(ids ...uuid.UUID) *TokenTransactionCreate {
	ttc.mutation.AddSparkInvoiceIDs(ids...)
	return ttc
}

// AddSparkInvoice adds the "spark_invoice" edges to the SparkInvoice entity.
func (ttc *TokenTransactionCreate) AddSparkInvoice(s ...*SparkInvoice) *TokenTransactionCreate {
	ids := make([]uuid.UUID, len(s))
	for i := range s {
		ids[i] = s[i].ID
	}
	return ttc.AddSparkInvoiceIDs(ids...)
}

// Mutation returns the TokenTransactionMutation object of the builder.
func (ttc *TokenTransactionCreate) Mutation() *TokenTransactionMutation {
	return ttc.mutation
}

// Save creates the TokenTransaction in the database.
func (ttc *TokenTransactionCreate) Save(ctx context.Context) (*TokenTransaction, error) {
	if err := ttc.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, ttc.sqlSave, ttc.mutation, ttc.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (ttc *TokenTransactionCreate) defaults() error {
	if _, ok := ttc.mutation.CreateTime(); !ok {
		if tokentransaction.DefaultCreateTime == nil {
			return fmt.Errorf("ent: uninitialized tokentransaction.DefaultCreateTime (forgotten import ent/runtime?)")
		}
		v := tokentransaction.DefaultCreateTime()
		ttc.mutation.SetCreateTime(v)
	}
	if _, ok := ttc.mutation.UpdateTime(); !ok {
		if tokentransaction.DefaultUpdateTime == nil {
			return fmt.Errorf("ent: uninitialized tokentransaction.DefaultUpdateTime (forgotten import ent/runtime?)")
		}
		v := tokentransaction.DefaultUpdateTime()
		ttc.mutation.SetUpdateTime(v)
	}
	if _, ok := ttc.mutation.Version(); !ok {
		v := tokentransaction.DefaultVersion
		ttc.mutation.SetVersion(v)
	}
	if _, ok := ttc.mutation.ID(); !ok {
		if tokentransaction.DefaultID == nil {
			return fmt.Errorf("ent: uninitialized tokentransaction.DefaultID (forgotten import ent/runtime?)")
		}
		v := tokentransaction.DefaultID()
		ttc.mutation.SetID(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (ttc *TokenTransactionCreate) check() error {
	if _, ok := ttc.mutation.CreateTime(); !ok {
		return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "TokenTransaction.create_time"`)}
	}
	if _, ok := ttc.mutation.UpdateTime(); !ok {
		return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "TokenTransaction.update_time"`)}
	}
	if _, ok := ttc.mutation.PartialTokenTransactionHash(); !ok {
		return &ValidationError{Name: "partial_token_transaction_hash", err: errors.New(`ent: missing required field "TokenTransaction.partial_token_transaction_hash"`)}
	}
	if v, ok := ttc.mutation.PartialTokenTransactionHash(); ok {
		if err := tokentransaction.PartialTokenTransactionHashValidator(v); err != nil {
			return &ValidationError{Name: "partial_token_transaction_hash", err: fmt.Errorf(`ent: validator failed for field "TokenTransaction.partial_token_transaction_hash": %w`, err)}
		}
	}
	if _, ok := ttc.mutation.FinalizedTokenTransactionHash(); !ok {
		return &ValidationError{Name: "finalized_token_transaction_hash", err: errors.New(`ent: missing required field "TokenTransaction.finalized_token_transaction_hash"`)}
	}
	if v, ok := ttc.mutation.FinalizedTokenTransactionHash(); ok {
		if err := tokentransaction.FinalizedTokenTransactionHashValidator(v); err != nil {
			return &ValidationError{Name: "finalized_token_transaction_hash", err: fmt.Errorf(`ent: validator failed for field "TokenTransaction.finalized_token_transaction_hash": %w`, err)}
		}
	}
	if v, ok := ttc.mutation.Status(); ok {
		if err := tokentransaction.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "TokenTransaction.status": %w`, err)}
		}
	}
	if _, ok := ttc.mutation.Version(); !ok {
		return &ValidationError{Name: "version", err: errors.New(`ent: missing required field "TokenTransaction.version"`)}
	}
	if v, ok := ttc.mutation.Version(); ok {
		if err := tokentransaction.VersionValidator(int(v)); err != nil {
			return &ValidationError{Name: "version", err: fmt.Errorf(`ent: validator failed for field "TokenTransaction.version": %w`, err)}
		}
	}
	return nil
}

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

func (ttc *TokenTransactionCreate) createSpec() (*TokenTransaction, *sqlgraph.CreateSpec) {
	var (
		_node = &TokenTransaction{config: ttc.config}
		_spec = sqlgraph.NewCreateSpec(tokentransaction.Table, sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID))
	)
	_spec.OnConflict = ttc.conflict
	if id, ok := ttc.mutation.ID(); ok {
		_node.ID = id
		_spec.ID.Value = &id
	}
	if value, ok := ttc.mutation.CreateTime(); ok {
		_spec.SetField(tokentransaction.FieldCreateTime, field.TypeTime, value)
		_node.CreateTime = value
	}
	if value, ok := ttc.mutation.UpdateTime(); ok {
		_spec.SetField(tokentransaction.FieldUpdateTime, field.TypeTime, value)
		_node.UpdateTime = value
	}
	if value, ok := ttc.mutation.PartialTokenTransactionHash(); ok {
		_spec.SetField(tokentransaction.FieldPartialTokenTransactionHash, field.TypeBytes, value)
		_node.PartialTokenTransactionHash = value
	}
	if value, ok := ttc.mutation.FinalizedTokenTransactionHash(); ok {
		_spec.SetField(tokentransaction.FieldFinalizedTokenTransactionHash, field.TypeBytes, value)
		_node.FinalizedTokenTransactionHash = value
	}
	if value, ok := ttc.mutation.OperatorSignature(); ok {
		_spec.SetField(tokentransaction.FieldOperatorSignature, field.TypeBytes, value)
		_node.OperatorSignature = value
	}
	if value, ok := ttc.mutation.Status(); ok {
		_spec.SetField(tokentransaction.FieldStatus, field.TypeEnum, value)
		_node.Status = value
	}
	if value, ok := ttc.mutation.ExpiryTime(); ok {
		_spec.SetField(tokentransaction.FieldExpiryTime, field.TypeTime, value)
		_node.ExpiryTime = value
	}
	if value, ok := ttc.mutation.CoordinatorPublicKey(); ok {
		_spec.SetField(tokentransaction.FieldCoordinatorPublicKey, field.TypeBytes, value)
		_node.CoordinatorPublicKey = value
	}
	if value, ok := ttc.mutation.ClientCreatedTimestamp(); ok {
		_spec.SetField(tokentransaction.FieldClientCreatedTimestamp, field.TypeTime, value)
		_node.ClientCreatedTimestamp = value
	}
	if value, ok := ttc.mutation.Version(); ok {
		_spec.SetField(tokentransaction.FieldVersion, field.TypeInt, value)
		_node.Version = value
	}
	if nodes := ttc.mutation.SpentOutputIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   tokentransaction.SpentOutputTable,
			Columns: []string{tokentransaction.SpentOutputColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenoutput.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.SpentOutputV2IDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: true,
			Table:   tokentransaction.SpentOutputV2Table,
			Columns: tokentransaction.SpentOutputV2PrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenoutput.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.CreatedOutputIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: true,
			Table:   tokentransaction.CreatedOutputTable,
			Columns: []string{tokentransaction.CreatedOutputColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenoutput.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.MintIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokentransaction.MintTable,
			Columns: []string{tokentransaction.MintColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenmint.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.token_transaction_mint = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.CreateIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokentransaction.CreateTable,
			Columns: []string{tokentransaction.CreateColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokencreate.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.token_transaction_create = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.PaymentIntentIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokentransaction.PaymentIntentTable,
			Columns: []string{tokentransaction.PaymentIntentColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(paymentintent.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_node.token_transaction_payment_intent = &nodes[0]
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.PeerSignaturesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokentransaction.PeerSignaturesTable,
			Columns: []string{tokentransaction.PeerSignaturesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransactionpeersignature.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges = append(_spec.Edges, edge)
	}
	if nodes := ttc.mutation.SparkInvoiceIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokentransaction.SparkInvoiceTable,
			Columns: tokentransaction.SparkInvoicePrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(sparkinvoice.FieldID, field.TypeUUID),
			},
		}
		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.TokenTransaction.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.TokenTransactionUpsert) {
//			SetCreateTime(v+v).
//		}).
//		Exec(ctx)
func (ttc *TokenTransactionCreate) OnConflict(opts ...sql.ConflictOption) *TokenTransactionUpsertOne {
	ttc.conflict = opts
	return &TokenTransactionUpsertOne{
		create: ttc,
	}
}

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

type (
	// TokenTransactionUpsertOne is the builder for "upsert"-ing
	//  one TokenTransaction node.
	TokenTransactionUpsertOne struct {
		create *TokenTransactionCreate
	}

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

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

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

// SetPartialTokenTransactionHash sets the "partial_token_transaction_hash" field.
func (u *TokenTransactionUpsert) SetPartialTokenTransactionHash(v []byte) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldPartialTokenTransactionHash, v)
	return u
}

// UpdatePartialTokenTransactionHash sets the "partial_token_transaction_hash" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdatePartialTokenTransactionHash() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldPartialTokenTransactionHash)
	return u
}

// SetFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field.
func (u *TokenTransactionUpsert) SetFinalizedTokenTransactionHash(v []byte) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldFinalizedTokenTransactionHash, v)
	return u
}

// UpdateFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdateFinalizedTokenTransactionHash() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldFinalizedTokenTransactionHash)
	return u
}

// SetOperatorSignature sets the "operator_signature" field.
func (u *TokenTransactionUpsert) SetOperatorSignature(v []byte) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldOperatorSignature, v)
	return u
}

// UpdateOperatorSignature sets the "operator_signature" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdateOperatorSignature() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldOperatorSignature)
	return u
}

// ClearOperatorSignature clears the value of the "operator_signature" field.
func (u *TokenTransactionUpsert) ClearOperatorSignature() *TokenTransactionUpsert {
	u.SetNull(tokentransaction.FieldOperatorSignature)
	return u
}

// SetStatus sets the "status" field.
func (u *TokenTransactionUpsert) SetStatus(v schematype.TokenTransactionStatus) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldStatus, v)
	return u
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdateStatus() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldStatus)
	return u
}

// ClearStatus clears the value of the "status" field.
func (u *TokenTransactionUpsert) ClearStatus() *TokenTransactionUpsert {
	u.SetNull(tokentransaction.FieldStatus)
	return u
}

// SetCoordinatorPublicKey sets the "coordinator_public_key" field.
func (u *TokenTransactionUpsert) SetCoordinatorPublicKey(v keys.Public) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldCoordinatorPublicKey, v)
	return u
}

// UpdateCoordinatorPublicKey sets the "coordinator_public_key" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdateCoordinatorPublicKey() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldCoordinatorPublicKey)
	return u
}

// ClearCoordinatorPublicKey clears the value of the "coordinator_public_key" field.
func (u *TokenTransactionUpsert) ClearCoordinatorPublicKey() *TokenTransactionUpsert {
	u.SetNull(tokentransaction.FieldCoordinatorPublicKey)
	return u
}

// SetClientCreatedTimestamp sets the "client_created_timestamp" field.
func (u *TokenTransactionUpsert) SetClientCreatedTimestamp(v time.Time) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldClientCreatedTimestamp, v)
	return u
}

// UpdateClientCreatedTimestamp sets the "client_created_timestamp" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdateClientCreatedTimestamp() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldClientCreatedTimestamp)
	return u
}

// ClearClientCreatedTimestamp clears the value of the "client_created_timestamp" field.
func (u *TokenTransactionUpsert) ClearClientCreatedTimestamp() *TokenTransactionUpsert {
	u.SetNull(tokentransaction.FieldClientCreatedTimestamp)
	return u
}

// SetVersion sets the "version" field.
func (u *TokenTransactionUpsert) SetVersion(v schematype.TokenTransactionVersion) *TokenTransactionUpsert {
	u.Set(tokentransaction.FieldVersion, v)
	return u
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *TokenTransactionUpsert) UpdateVersion() *TokenTransactionUpsert {
	u.SetExcluded(tokentransaction.FieldVersion)
	return u
}

// AddVersion adds v to the "version" field.
func (u *TokenTransactionUpsert) AddVersion(v schematype.TokenTransactionVersion) *TokenTransactionUpsert {
	u.Add(tokentransaction.FieldVersion, v)
	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.TokenTransaction.Create().
//		OnConflict(
//			sql.ResolveWithNewValues(),
//			sql.ResolveWith(func(u *sql.UpdateSet) {
//				u.SetIgnore(tokentransaction.FieldID)
//			}),
//		).
//		Exec(ctx)
func (u *TokenTransactionUpsertOne) UpdateNewValues() *TokenTransactionUpsertOne {
	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(tokentransaction.FieldID)
		}
		if _, exists := u.create.mutation.CreateTime(); exists {
			s.SetIgnore(tokentransaction.FieldCreateTime)
		}
		if _, exists := u.create.mutation.ExpiryTime(); exists {
			s.SetIgnore(tokentransaction.FieldExpiryTime)
		}
	}))
	return u
}

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

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

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

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

// SetPartialTokenTransactionHash sets the "partial_token_transaction_hash" field.
func (u *TokenTransactionUpsertOne) SetPartialTokenTransactionHash(v []byte) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetPartialTokenTransactionHash(v)
	})
}

// UpdatePartialTokenTransactionHash sets the "partial_token_transaction_hash" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdatePartialTokenTransactionHash() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdatePartialTokenTransactionHash()
	})
}

// SetFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field.
func (u *TokenTransactionUpsertOne) SetFinalizedTokenTransactionHash(v []byte) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetFinalizedTokenTransactionHash(v)
	})
}

// UpdateFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdateFinalizedTokenTransactionHash() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateFinalizedTokenTransactionHash()
	})
}

// SetOperatorSignature sets the "operator_signature" field.
func (u *TokenTransactionUpsertOne) SetOperatorSignature(v []byte) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetOperatorSignature(v)
	})
}

// UpdateOperatorSignature sets the "operator_signature" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdateOperatorSignature() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateOperatorSignature()
	})
}

// ClearOperatorSignature clears the value of the "operator_signature" field.
func (u *TokenTransactionUpsertOne) ClearOperatorSignature() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearOperatorSignature()
	})
}

// SetStatus sets the "status" field.
func (u *TokenTransactionUpsertOne) SetStatus(v schematype.TokenTransactionStatus) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdateStatus() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateStatus()
	})
}

// ClearStatus clears the value of the "status" field.
func (u *TokenTransactionUpsertOne) ClearStatus() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearStatus()
	})
}

// SetCoordinatorPublicKey sets the "coordinator_public_key" field.
func (u *TokenTransactionUpsertOne) SetCoordinatorPublicKey(v keys.Public) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetCoordinatorPublicKey(v)
	})
}

// UpdateCoordinatorPublicKey sets the "coordinator_public_key" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdateCoordinatorPublicKey() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateCoordinatorPublicKey()
	})
}

// ClearCoordinatorPublicKey clears the value of the "coordinator_public_key" field.
func (u *TokenTransactionUpsertOne) ClearCoordinatorPublicKey() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearCoordinatorPublicKey()
	})
}

// SetClientCreatedTimestamp sets the "client_created_timestamp" field.
func (u *TokenTransactionUpsertOne) SetClientCreatedTimestamp(v time.Time) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetClientCreatedTimestamp(v)
	})
}

// UpdateClientCreatedTimestamp sets the "client_created_timestamp" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdateClientCreatedTimestamp() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateClientCreatedTimestamp()
	})
}

// ClearClientCreatedTimestamp clears the value of the "client_created_timestamp" field.
func (u *TokenTransactionUpsertOne) ClearClientCreatedTimestamp() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearClientCreatedTimestamp()
	})
}

// SetVersion sets the "version" field.
func (u *TokenTransactionUpsertOne) SetVersion(v schematype.TokenTransactionVersion) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetVersion(v)
	})
}

// AddVersion adds v to the "version" field.
func (u *TokenTransactionUpsertOne) AddVersion(v schematype.TokenTransactionVersion) *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.AddVersion(v)
	})
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *TokenTransactionUpsertOne) UpdateVersion() *TokenTransactionUpsertOne {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateVersion()
	})
}

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

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

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

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

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

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

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

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

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

// TokenTransactionUpsertBulk is the builder for "upsert"-ing
// a bulk of TokenTransaction nodes.
type TokenTransactionUpsertBulk struct {
	create *TokenTransactionCreateBulk
}

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

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

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

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

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

// SetPartialTokenTransactionHash sets the "partial_token_transaction_hash" field.
func (u *TokenTransactionUpsertBulk) SetPartialTokenTransactionHash(v []byte) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetPartialTokenTransactionHash(v)
	})
}

// UpdatePartialTokenTransactionHash sets the "partial_token_transaction_hash" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdatePartialTokenTransactionHash() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdatePartialTokenTransactionHash()
	})
}

// SetFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field.
func (u *TokenTransactionUpsertBulk) SetFinalizedTokenTransactionHash(v []byte) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetFinalizedTokenTransactionHash(v)
	})
}

// UpdateFinalizedTokenTransactionHash sets the "finalized_token_transaction_hash" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdateFinalizedTokenTransactionHash() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateFinalizedTokenTransactionHash()
	})
}

// SetOperatorSignature sets the "operator_signature" field.
func (u *TokenTransactionUpsertBulk) SetOperatorSignature(v []byte) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetOperatorSignature(v)
	})
}

// UpdateOperatorSignature sets the "operator_signature" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdateOperatorSignature() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateOperatorSignature()
	})
}

// ClearOperatorSignature clears the value of the "operator_signature" field.
func (u *TokenTransactionUpsertBulk) ClearOperatorSignature() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearOperatorSignature()
	})
}

// SetStatus sets the "status" field.
func (u *TokenTransactionUpsertBulk) SetStatus(v schematype.TokenTransactionStatus) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetStatus(v)
	})
}

// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdateStatus() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateStatus()
	})
}

// ClearStatus clears the value of the "status" field.
func (u *TokenTransactionUpsertBulk) ClearStatus() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearStatus()
	})
}

// SetCoordinatorPublicKey sets the "coordinator_public_key" field.
func (u *TokenTransactionUpsertBulk) SetCoordinatorPublicKey(v keys.Public) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetCoordinatorPublicKey(v)
	})
}

// UpdateCoordinatorPublicKey sets the "coordinator_public_key" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdateCoordinatorPublicKey() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateCoordinatorPublicKey()
	})
}

// ClearCoordinatorPublicKey clears the value of the "coordinator_public_key" field.
func (u *TokenTransactionUpsertBulk) ClearCoordinatorPublicKey() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearCoordinatorPublicKey()
	})
}

// SetClientCreatedTimestamp sets the "client_created_timestamp" field.
func (u *TokenTransactionUpsertBulk) SetClientCreatedTimestamp(v time.Time) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetClientCreatedTimestamp(v)
	})
}

// UpdateClientCreatedTimestamp sets the "client_created_timestamp" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdateClientCreatedTimestamp() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateClientCreatedTimestamp()
	})
}

// ClearClientCreatedTimestamp clears the value of the "client_created_timestamp" field.
func (u *TokenTransactionUpsertBulk) ClearClientCreatedTimestamp() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.ClearClientCreatedTimestamp()
	})
}

// SetVersion sets the "version" field.
func (u *TokenTransactionUpsertBulk) SetVersion(v schematype.TokenTransactionVersion) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.SetVersion(v)
	})
}

// AddVersion adds v to the "version" field.
func (u *TokenTransactionUpsertBulk) AddVersion(v schematype.TokenTransactionVersion) *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.AddVersion(v)
	})
}

// UpdateVersion sets the "version" field to the value that was provided on create.
func (u *TokenTransactionUpsertBulk) UpdateVersion() *TokenTransactionUpsertBulk {
	return u.Update(func(s *TokenTransactionUpsert) {
		s.UpdateVersion()
	})
}

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

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