// Code generated by ent, DO NOT EDIT.

package ent

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

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
	"github.com/google/uuid"
	"github.com/lightsparkdev/spark/common/keys"
	"github.com/lightsparkdev/spark/so/ent/predicate"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
	"github.com/lightsparkdev/spark/so/ent/tokenoutput"
	"github.com/lightsparkdev/spark/so/ent/tokenpartialrevocationsecretshare"
	"github.com/lightsparkdev/spark/so/ent/tokentransaction"
)

// TokenOutputUpdate is the builder for updating TokenOutput entities.
type TokenOutputUpdate struct {
	config
	hooks    []Hook
	mutation *TokenOutputMutation
}

// Where appends a list predicates to the TokenOutputUpdate builder.
func (tou *TokenOutputUpdate) Where(ps ...predicate.TokenOutput) *TokenOutputUpdate {
	tou.mutation.Where(ps...)
	return tou
}

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

// SetStatus sets the "status" field.
func (tou *TokenOutputUpdate) SetStatus(sos schematype.TokenOutputStatus) *TokenOutputUpdate {
	tou.mutation.SetStatus(sos)
	return tou
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (tou *TokenOutputUpdate) SetNillableStatus(sos *schematype.TokenOutputStatus) *TokenOutputUpdate {
	if sos != nil {
		tou.SetStatus(*sos)
	}
	return tou
}

// SetSpentOwnershipSignature sets the "spent_ownership_signature" field.
func (tou *TokenOutputUpdate) SetSpentOwnershipSignature(b []byte) *TokenOutputUpdate {
	tou.mutation.SetSpentOwnershipSignature(b)
	return tou
}

// ClearSpentOwnershipSignature clears the value of the "spent_ownership_signature" field.
func (tou *TokenOutputUpdate) ClearSpentOwnershipSignature() *TokenOutputUpdate {
	tou.mutation.ClearSpentOwnershipSignature()
	return tou
}

// SetSpentOperatorSpecificOwnershipSignature sets the "spent_operator_specific_ownership_signature" field.
func (tou *TokenOutputUpdate) SetSpentOperatorSpecificOwnershipSignature(b []byte) *TokenOutputUpdate {
	tou.mutation.SetSpentOperatorSpecificOwnershipSignature(b)
	return tou
}

// ClearSpentOperatorSpecificOwnershipSignature clears the value of the "spent_operator_specific_ownership_signature" field.
func (tou *TokenOutputUpdate) ClearSpentOperatorSpecificOwnershipSignature() *TokenOutputUpdate {
	tou.mutation.ClearSpentOperatorSpecificOwnershipSignature()
	return tou
}

// SetSpentTransactionInputVout sets the "spent_transaction_input_vout" field.
func (tou *TokenOutputUpdate) SetSpentTransactionInputVout(i int32) *TokenOutputUpdate {
	tou.mutation.ResetSpentTransactionInputVout()
	tou.mutation.SetSpentTransactionInputVout(i)
	return tou
}

// SetNillableSpentTransactionInputVout sets the "spent_transaction_input_vout" field if the given value is not nil.
func (tou *TokenOutputUpdate) SetNillableSpentTransactionInputVout(i *int32) *TokenOutputUpdate {
	if i != nil {
		tou.SetSpentTransactionInputVout(*i)
	}
	return tou
}

// AddSpentTransactionInputVout adds i to the "spent_transaction_input_vout" field.
func (tou *TokenOutputUpdate) AddSpentTransactionInputVout(i int32) *TokenOutputUpdate {
	tou.mutation.AddSpentTransactionInputVout(i)
	return tou
}

// ClearSpentTransactionInputVout clears the value of the "spent_transaction_input_vout" field.
func (tou *TokenOutputUpdate) ClearSpentTransactionInputVout() *TokenOutputUpdate {
	tou.mutation.ClearSpentTransactionInputVout()
	return tou
}

// SetSpentRevocationSecret sets the "spent_revocation_secret" field.
func (tou *TokenOutputUpdate) SetSpentRevocationSecret(k keys.Private) *TokenOutputUpdate {
	tou.mutation.SetSpentRevocationSecret(k)
	return tou
}

// SetNillableSpentRevocationSecret sets the "spent_revocation_secret" field if the given value is not nil.
func (tou *TokenOutputUpdate) SetNillableSpentRevocationSecret(k *keys.Private) *TokenOutputUpdate {
	if k != nil {
		tou.SetSpentRevocationSecret(*k)
	}
	return tou
}

// ClearSpentRevocationSecret clears the value of the "spent_revocation_secret" field.
func (tou *TokenOutputUpdate) ClearSpentRevocationSecret() *TokenOutputUpdate {
	tou.mutation.ClearSpentRevocationSecret()
	return tou
}

// SetConfirmedWithdrawBlockHash sets the "confirmed_withdraw_block_hash" field.
func (tou *TokenOutputUpdate) SetConfirmedWithdrawBlockHash(b []byte) *TokenOutputUpdate {
	tou.mutation.SetConfirmedWithdrawBlockHash(b)
	return tou
}

// ClearConfirmedWithdrawBlockHash clears the value of the "confirmed_withdraw_block_hash" field.
func (tou *TokenOutputUpdate) ClearConfirmedWithdrawBlockHash() *TokenOutputUpdate {
	tou.mutation.ClearConfirmedWithdrawBlockHash()
	return tou
}

// SetNetwork sets the "network" field.
func (tou *TokenOutputUpdate) SetNetwork(s schematype.Network) *TokenOutputUpdate {
	tou.mutation.SetNetwork(s)
	return tou
}

// SetNillableNetwork sets the "network" field if the given value is not nil.
func (tou *TokenOutputUpdate) SetNillableNetwork(s *schematype.Network) *TokenOutputUpdate {
	if s != nil {
		tou.SetNetwork(*s)
	}
	return tou
}

// ClearNetwork clears the value of the "network" field.
func (tou *TokenOutputUpdate) ClearNetwork() *TokenOutputUpdate {
	tou.mutation.ClearNetwork()
	return tou
}

// SetOutputCreatedTokenTransactionID sets the "output_created_token_transaction" edge to the TokenTransaction entity by ID.
func (tou *TokenOutputUpdate) SetOutputCreatedTokenTransactionID(id uuid.UUID) *TokenOutputUpdate {
	tou.mutation.SetOutputCreatedTokenTransactionID(id)
	return tou
}

// SetNillableOutputCreatedTokenTransactionID sets the "output_created_token_transaction" edge to the TokenTransaction entity by ID if the given value is not nil.
func (tou *TokenOutputUpdate) SetNillableOutputCreatedTokenTransactionID(id *uuid.UUID) *TokenOutputUpdate {
	if id != nil {
		tou = tou.SetOutputCreatedTokenTransactionID(*id)
	}
	return tou
}

// SetOutputCreatedTokenTransaction sets the "output_created_token_transaction" edge to the TokenTransaction entity.
func (tou *TokenOutputUpdate) SetOutputCreatedTokenTransaction(t *TokenTransaction) *TokenOutputUpdate {
	return tou.SetOutputCreatedTokenTransactionID(t.ID)
}

// SetOutputSpentTokenTransactionID sets the "output_spent_token_transaction" edge to the TokenTransaction entity by ID.
func (tou *TokenOutputUpdate) SetOutputSpentTokenTransactionID(id uuid.UUID) *TokenOutputUpdate {
	tou.mutation.SetOutputSpentTokenTransactionID(id)
	return tou
}

// SetNillableOutputSpentTokenTransactionID sets the "output_spent_token_transaction" edge to the TokenTransaction entity by ID if the given value is not nil.
func (tou *TokenOutputUpdate) SetNillableOutputSpentTokenTransactionID(id *uuid.UUID) *TokenOutputUpdate {
	if id != nil {
		tou = tou.SetOutputSpentTokenTransactionID(*id)
	}
	return tou
}

// SetOutputSpentTokenTransaction sets the "output_spent_token_transaction" edge to the TokenTransaction entity.
func (tou *TokenOutputUpdate) SetOutputSpentTokenTransaction(t *TokenTransaction) *TokenOutputUpdate {
	return tou.SetOutputSpentTokenTransactionID(t.ID)
}

// AddOutputSpentStartedTokenTransactionIDs adds the "output_spent_started_token_transactions" edge to the TokenTransaction entity by IDs.
func (tou *TokenOutputUpdate) AddOutputSpentStartedTokenTransactionIDs(ids ...uuid.UUID) *TokenOutputUpdate {
	tou.mutation.AddOutputSpentStartedTokenTransactionIDs(ids...)
	return tou
}

// AddOutputSpentStartedTokenTransactions adds the "output_spent_started_token_transactions" edges to the TokenTransaction entity.
func (tou *TokenOutputUpdate) AddOutputSpentStartedTokenTransactions(t ...*TokenTransaction) *TokenOutputUpdate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return tou.AddOutputSpentStartedTokenTransactionIDs(ids...)
}

// AddTokenPartialRevocationSecretShareIDs adds the "token_partial_revocation_secret_shares" edge to the TokenPartialRevocationSecretShare entity by IDs.
func (tou *TokenOutputUpdate) AddTokenPartialRevocationSecretShareIDs(ids ...uuid.UUID) *TokenOutputUpdate {
	tou.mutation.AddTokenPartialRevocationSecretShareIDs(ids...)
	return tou
}

// AddTokenPartialRevocationSecretShares adds the "token_partial_revocation_secret_shares" edges to the TokenPartialRevocationSecretShare entity.
func (tou *TokenOutputUpdate) AddTokenPartialRevocationSecretShares(t ...*TokenPartialRevocationSecretShare) *TokenOutputUpdate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return tou.AddTokenPartialRevocationSecretShareIDs(ids...)
}

// Mutation returns the TokenOutputMutation object of the builder.
func (tou *TokenOutputUpdate) Mutation() *TokenOutputMutation {
	return tou.mutation
}

// ClearOutputCreatedTokenTransaction clears the "output_created_token_transaction" edge to the TokenTransaction entity.
func (tou *TokenOutputUpdate) ClearOutputCreatedTokenTransaction() *TokenOutputUpdate {
	tou.mutation.ClearOutputCreatedTokenTransaction()
	return tou
}

// ClearOutputSpentTokenTransaction clears the "output_spent_token_transaction" edge to the TokenTransaction entity.
func (tou *TokenOutputUpdate) ClearOutputSpentTokenTransaction() *TokenOutputUpdate {
	tou.mutation.ClearOutputSpentTokenTransaction()
	return tou
}

// ClearOutputSpentStartedTokenTransactions clears all "output_spent_started_token_transactions" edges to the TokenTransaction entity.
func (tou *TokenOutputUpdate) ClearOutputSpentStartedTokenTransactions() *TokenOutputUpdate {
	tou.mutation.ClearOutputSpentStartedTokenTransactions()
	return tou
}

// RemoveOutputSpentStartedTokenTransactionIDs removes the "output_spent_started_token_transactions" edge to TokenTransaction entities by IDs.
func (tou *TokenOutputUpdate) RemoveOutputSpentStartedTokenTransactionIDs(ids ...uuid.UUID) *TokenOutputUpdate {
	tou.mutation.RemoveOutputSpentStartedTokenTransactionIDs(ids...)
	return tou
}

// RemoveOutputSpentStartedTokenTransactions removes "output_spent_started_token_transactions" edges to TokenTransaction entities.
func (tou *TokenOutputUpdate) RemoveOutputSpentStartedTokenTransactions(t ...*TokenTransaction) *TokenOutputUpdate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return tou.RemoveOutputSpentStartedTokenTransactionIDs(ids...)
}

// ClearTokenPartialRevocationSecretShares clears all "token_partial_revocation_secret_shares" edges to the TokenPartialRevocationSecretShare entity.
func (tou *TokenOutputUpdate) ClearTokenPartialRevocationSecretShares() *TokenOutputUpdate {
	tou.mutation.ClearTokenPartialRevocationSecretShares()
	return tou
}

// RemoveTokenPartialRevocationSecretShareIDs removes the "token_partial_revocation_secret_shares" edge to TokenPartialRevocationSecretShare entities by IDs.
func (tou *TokenOutputUpdate) RemoveTokenPartialRevocationSecretShareIDs(ids ...uuid.UUID) *TokenOutputUpdate {
	tou.mutation.RemoveTokenPartialRevocationSecretShareIDs(ids...)
	return tou
}

// RemoveTokenPartialRevocationSecretShares removes "token_partial_revocation_secret_shares" edges to TokenPartialRevocationSecretShare entities.
func (tou *TokenOutputUpdate) RemoveTokenPartialRevocationSecretShares(t ...*TokenPartialRevocationSecretShare) *TokenOutputUpdate {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return tou.RemoveTokenPartialRevocationSecretShareIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (tou *TokenOutputUpdate) Save(ctx context.Context) (int, error) {
	if err := tou.defaults(); err != nil {
		return 0, err
	}
	return withHooks(ctx, tou.sqlSave, tou.mutation, tou.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (tou *TokenOutputUpdate) defaults() error {
	if _, ok := tou.mutation.UpdateTime(); !ok {
		if tokenoutput.UpdateDefaultUpdateTime == nil {
			return fmt.Errorf("ent: uninitialized tokenoutput.UpdateDefaultUpdateTime (forgotten import ent/runtime?)")
		}
		v := tokenoutput.UpdateDefaultUpdateTime()
		tou.mutation.SetUpdateTime(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (tou *TokenOutputUpdate) check() error {
	if v, ok := tou.mutation.Status(); ok {
		if err := tokenoutput.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "TokenOutput.status": %w`, err)}
		}
	}
	if v, ok := tou.mutation.Network(); ok {
		if err := tokenoutput.NetworkValidator(v); err != nil {
			return &ValidationError{Name: "network", err: fmt.Errorf(`ent: validator failed for field "TokenOutput.network": %w`, err)}
		}
	}
	if tou.mutation.RevocationKeyshareCleared() && len(tou.mutation.RevocationKeyshareIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TokenOutput.revocation_keyshare"`)
	}
	if tou.mutation.TokenCreateCleared() && len(tou.mutation.TokenCreateIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TokenOutput.token_create"`)
	}
	return nil
}

func (tou *TokenOutputUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := tou.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(tokenoutput.Table, tokenoutput.Columns, sqlgraph.NewFieldSpec(tokenoutput.FieldID, field.TypeUUID))
	if ps := tou.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := tou.mutation.UpdateTime(); ok {
		_spec.SetField(tokenoutput.FieldUpdateTime, field.TypeTime, value)
	}
	if value, ok := tou.mutation.Status(); ok {
		_spec.SetField(tokenoutput.FieldStatus, field.TypeEnum, value)
	}
	if tou.mutation.TokenPublicKeyCleared() {
		_spec.ClearField(tokenoutput.FieldTokenPublicKey, field.TypeBytes)
	}
	if value, ok := tou.mutation.SpentOwnershipSignature(); ok {
		_spec.SetField(tokenoutput.FieldSpentOwnershipSignature, field.TypeBytes, value)
	}
	if tou.mutation.SpentOwnershipSignatureCleared() {
		_spec.ClearField(tokenoutput.FieldSpentOwnershipSignature, field.TypeBytes)
	}
	if value, ok := tou.mutation.SpentOperatorSpecificOwnershipSignature(); ok {
		_spec.SetField(tokenoutput.FieldSpentOperatorSpecificOwnershipSignature, field.TypeBytes, value)
	}
	if tou.mutation.SpentOperatorSpecificOwnershipSignatureCleared() {
		_spec.ClearField(tokenoutput.FieldSpentOperatorSpecificOwnershipSignature, field.TypeBytes)
	}
	if value, ok := tou.mutation.SpentTransactionInputVout(); ok {
		_spec.SetField(tokenoutput.FieldSpentTransactionInputVout, field.TypeInt32, value)
	}
	if value, ok := tou.mutation.AddedSpentTransactionInputVout(); ok {
		_spec.AddField(tokenoutput.FieldSpentTransactionInputVout, field.TypeInt32, value)
	}
	if tou.mutation.SpentTransactionInputVoutCleared() {
		_spec.ClearField(tokenoutput.FieldSpentTransactionInputVout, field.TypeInt32)
	}
	if value, ok := tou.mutation.SpentRevocationSecret(); ok {
		_spec.SetField(tokenoutput.FieldSpentRevocationSecret, field.TypeBytes, value)
	}
	if tou.mutation.SpentRevocationSecretCleared() {
		_spec.ClearField(tokenoutput.FieldSpentRevocationSecret, field.TypeBytes)
	}
	if value, ok := tou.mutation.ConfirmedWithdrawBlockHash(); ok {
		_spec.SetField(tokenoutput.FieldConfirmedWithdrawBlockHash, field.TypeBytes, value)
	}
	if tou.mutation.ConfirmedWithdrawBlockHashCleared() {
		_spec.ClearField(tokenoutput.FieldConfirmedWithdrawBlockHash, field.TypeBytes)
	}
	if value, ok := tou.mutation.Network(); ok {
		_spec.SetField(tokenoutput.FieldNetwork, field.TypeEnum, value)
	}
	if tou.mutation.NetworkCleared() {
		_spec.ClearField(tokenoutput.FieldNetwork, field.TypeEnum)
	}
	if tou.mutation.OutputCreatedTokenTransactionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputCreatedTokenTransactionTable,
			Columns: []string{tokenoutput.OutputCreatedTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tou.mutation.OutputCreatedTokenTransactionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputCreatedTokenTransactionTable,
			Columns: []string{tokenoutput.OutputCreatedTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if tou.mutation.OutputSpentTokenTransactionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputSpentTokenTransactionTable,
			Columns: []string{tokenoutput.OutputSpentTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tou.mutation.OutputSpentTokenTransactionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputSpentTokenTransactionTable,
			Columns: []string{tokenoutput.OutputSpentTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if tou.mutation.OutputSpentStartedTokenTransactionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokenoutput.OutputSpentStartedTokenTransactionsTable,
			Columns: tokenoutput.OutputSpentStartedTokenTransactionsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tou.mutation.RemovedOutputSpentStartedTokenTransactionsIDs(); len(nodes) > 0 && !tou.mutation.OutputSpentStartedTokenTransactionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokenoutput.OutputSpentStartedTokenTransactionsTable,
			Columns: tokenoutput.OutputSpentStartedTokenTransactionsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tou.mutation.OutputSpentStartedTokenTransactionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokenoutput.OutputSpentStartedTokenTransactionsTable,
			Columns: tokenoutput.OutputSpentStartedTokenTransactionsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if tou.mutation.TokenPartialRevocationSecretSharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokenoutput.TokenPartialRevocationSecretSharesTable,
			Columns: []string{tokenoutput.TokenPartialRevocationSecretSharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tou.mutation.RemovedTokenPartialRevocationSecretSharesIDs(); len(nodes) > 0 && !tou.mutation.TokenPartialRevocationSecretSharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokenoutput.TokenPartialRevocationSecretSharesTable,
			Columns: []string{tokenoutput.TokenPartialRevocationSecretSharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tou.mutation.TokenPartialRevocationSecretSharesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokenoutput.TokenPartialRevocationSecretSharesTable,
			Columns: []string{tokenoutput.TokenPartialRevocationSecretSharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, tou.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{tokenoutput.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	tou.mutation.done = true
	return n, nil
}

// TokenOutputUpdateOne is the builder for updating a single TokenOutput entity.
type TokenOutputUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *TokenOutputMutation
}

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

// SetStatus sets the "status" field.
func (touo *TokenOutputUpdateOne) SetStatus(sos schematype.TokenOutputStatus) *TokenOutputUpdateOne {
	touo.mutation.SetStatus(sos)
	return touo
}

// SetNillableStatus sets the "status" field if the given value is not nil.
func (touo *TokenOutputUpdateOne) SetNillableStatus(sos *schematype.TokenOutputStatus) *TokenOutputUpdateOne {
	if sos != nil {
		touo.SetStatus(*sos)
	}
	return touo
}

// SetSpentOwnershipSignature sets the "spent_ownership_signature" field.
func (touo *TokenOutputUpdateOne) SetSpentOwnershipSignature(b []byte) *TokenOutputUpdateOne {
	touo.mutation.SetSpentOwnershipSignature(b)
	return touo
}

// ClearSpentOwnershipSignature clears the value of the "spent_ownership_signature" field.
func (touo *TokenOutputUpdateOne) ClearSpentOwnershipSignature() *TokenOutputUpdateOne {
	touo.mutation.ClearSpentOwnershipSignature()
	return touo
}

// SetSpentOperatorSpecificOwnershipSignature sets the "spent_operator_specific_ownership_signature" field.
func (touo *TokenOutputUpdateOne) SetSpentOperatorSpecificOwnershipSignature(b []byte) *TokenOutputUpdateOne {
	touo.mutation.SetSpentOperatorSpecificOwnershipSignature(b)
	return touo
}

// ClearSpentOperatorSpecificOwnershipSignature clears the value of the "spent_operator_specific_ownership_signature" field.
func (touo *TokenOutputUpdateOne) ClearSpentOperatorSpecificOwnershipSignature() *TokenOutputUpdateOne {
	touo.mutation.ClearSpentOperatorSpecificOwnershipSignature()
	return touo
}

// SetSpentTransactionInputVout sets the "spent_transaction_input_vout" field.
func (touo *TokenOutputUpdateOne) SetSpentTransactionInputVout(i int32) *TokenOutputUpdateOne {
	touo.mutation.ResetSpentTransactionInputVout()
	touo.mutation.SetSpentTransactionInputVout(i)
	return touo
}

// SetNillableSpentTransactionInputVout sets the "spent_transaction_input_vout" field if the given value is not nil.
func (touo *TokenOutputUpdateOne) SetNillableSpentTransactionInputVout(i *int32) *TokenOutputUpdateOne {
	if i != nil {
		touo.SetSpentTransactionInputVout(*i)
	}
	return touo
}

// AddSpentTransactionInputVout adds i to the "spent_transaction_input_vout" field.
func (touo *TokenOutputUpdateOne) AddSpentTransactionInputVout(i int32) *TokenOutputUpdateOne {
	touo.mutation.AddSpentTransactionInputVout(i)
	return touo
}

// ClearSpentTransactionInputVout clears the value of the "spent_transaction_input_vout" field.
func (touo *TokenOutputUpdateOne) ClearSpentTransactionInputVout() *TokenOutputUpdateOne {
	touo.mutation.ClearSpentTransactionInputVout()
	return touo
}

// SetSpentRevocationSecret sets the "spent_revocation_secret" field.
func (touo *TokenOutputUpdateOne) SetSpentRevocationSecret(k keys.Private) *TokenOutputUpdateOne {
	touo.mutation.SetSpentRevocationSecret(k)
	return touo
}

// SetNillableSpentRevocationSecret sets the "spent_revocation_secret" field if the given value is not nil.
func (touo *TokenOutputUpdateOne) SetNillableSpentRevocationSecret(k *keys.Private) *TokenOutputUpdateOne {
	if k != nil {
		touo.SetSpentRevocationSecret(*k)
	}
	return touo
}

// ClearSpentRevocationSecret clears the value of the "spent_revocation_secret" field.
func (touo *TokenOutputUpdateOne) ClearSpentRevocationSecret() *TokenOutputUpdateOne {
	touo.mutation.ClearSpentRevocationSecret()
	return touo
}

// SetConfirmedWithdrawBlockHash sets the "confirmed_withdraw_block_hash" field.
func (touo *TokenOutputUpdateOne) SetConfirmedWithdrawBlockHash(b []byte) *TokenOutputUpdateOne {
	touo.mutation.SetConfirmedWithdrawBlockHash(b)
	return touo
}

// ClearConfirmedWithdrawBlockHash clears the value of the "confirmed_withdraw_block_hash" field.
func (touo *TokenOutputUpdateOne) ClearConfirmedWithdrawBlockHash() *TokenOutputUpdateOne {
	touo.mutation.ClearConfirmedWithdrawBlockHash()
	return touo
}

// SetNetwork sets the "network" field.
func (touo *TokenOutputUpdateOne) SetNetwork(s schematype.Network) *TokenOutputUpdateOne {
	touo.mutation.SetNetwork(s)
	return touo
}

// SetNillableNetwork sets the "network" field if the given value is not nil.
func (touo *TokenOutputUpdateOne) SetNillableNetwork(s *schematype.Network) *TokenOutputUpdateOne {
	if s != nil {
		touo.SetNetwork(*s)
	}
	return touo
}

// ClearNetwork clears the value of the "network" field.
func (touo *TokenOutputUpdateOne) ClearNetwork() *TokenOutputUpdateOne {
	touo.mutation.ClearNetwork()
	return touo
}

// SetOutputCreatedTokenTransactionID sets the "output_created_token_transaction" edge to the TokenTransaction entity by ID.
func (touo *TokenOutputUpdateOne) SetOutputCreatedTokenTransactionID(id uuid.UUID) *TokenOutputUpdateOne {
	touo.mutation.SetOutputCreatedTokenTransactionID(id)
	return touo
}

// SetNillableOutputCreatedTokenTransactionID sets the "output_created_token_transaction" edge to the TokenTransaction entity by ID if the given value is not nil.
func (touo *TokenOutputUpdateOne) SetNillableOutputCreatedTokenTransactionID(id *uuid.UUID) *TokenOutputUpdateOne {
	if id != nil {
		touo = touo.SetOutputCreatedTokenTransactionID(*id)
	}
	return touo
}

// SetOutputCreatedTokenTransaction sets the "output_created_token_transaction" edge to the TokenTransaction entity.
func (touo *TokenOutputUpdateOne) SetOutputCreatedTokenTransaction(t *TokenTransaction) *TokenOutputUpdateOne {
	return touo.SetOutputCreatedTokenTransactionID(t.ID)
}

// SetOutputSpentTokenTransactionID sets the "output_spent_token_transaction" edge to the TokenTransaction entity by ID.
func (touo *TokenOutputUpdateOne) SetOutputSpentTokenTransactionID(id uuid.UUID) *TokenOutputUpdateOne {
	touo.mutation.SetOutputSpentTokenTransactionID(id)
	return touo
}

// SetNillableOutputSpentTokenTransactionID sets the "output_spent_token_transaction" edge to the TokenTransaction entity by ID if the given value is not nil.
func (touo *TokenOutputUpdateOne) SetNillableOutputSpentTokenTransactionID(id *uuid.UUID) *TokenOutputUpdateOne {
	if id != nil {
		touo = touo.SetOutputSpentTokenTransactionID(*id)
	}
	return touo
}

// SetOutputSpentTokenTransaction sets the "output_spent_token_transaction" edge to the TokenTransaction entity.
func (touo *TokenOutputUpdateOne) SetOutputSpentTokenTransaction(t *TokenTransaction) *TokenOutputUpdateOne {
	return touo.SetOutputSpentTokenTransactionID(t.ID)
}

// AddOutputSpentStartedTokenTransactionIDs adds the "output_spent_started_token_transactions" edge to the TokenTransaction entity by IDs.
func (touo *TokenOutputUpdateOne) AddOutputSpentStartedTokenTransactionIDs(ids ...uuid.UUID) *TokenOutputUpdateOne {
	touo.mutation.AddOutputSpentStartedTokenTransactionIDs(ids...)
	return touo
}

// AddOutputSpentStartedTokenTransactions adds the "output_spent_started_token_transactions" edges to the TokenTransaction entity.
func (touo *TokenOutputUpdateOne) AddOutputSpentStartedTokenTransactions(t ...*TokenTransaction) *TokenOutputUpdateOne {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return touo.AddOutputSpentStartedTokenTransactionIDs(ids...)
}

// AddTokenPartialRevocationSecretShareIDs adds the "token_partial_revocation_secret_shares" edge to the TokenPartialRevocationSecretShare entity by IDs.
func (touo *TokenOutputUpdateOne) AddTokenPartialRevocationSecretShareIDs(ids ...uuid.UUID) *TokenOutputUpdateOne {
	touo.mutation.AddTokenPartialRevocationSecretShareIDs(ids...)
	return touo
}

// AddTokenPartialRevocationSecretShares adds the "token_partial_revocation_secret_shares" edges to the TokenPartialRevocationSecretShare entity.
func (touo *TokenOutputUpdateOne) AddTokenPartialRevocationSecretShares(t ...*TokenPartialRevocationSecretShare) *TokenOutputUpdateOne {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return touo.AddTokenPartialRevocationSecretShareIDs(ids...)
}

// Mutation returns the TokenOutputMutation object of the builder.
func (touo *TokenOutputUpdateOne) Mutation() *TokenOutputMutation {
	return touo.mutation
}

// ClearOutputCreatedTokenTransaction clears the "output_created_token_transaction" edge to the TokenTransaction entity.
func (touo *TokenOutputUpdateOne) ClearOutputCreatedTokenTransaction() *TokenOutputUpdateOne {
	touo.mutation.ClearOutputCreatedTokenTransaction()
	return touo
}

// ClearOutputSpentTokenTransaction clears the "output_spent_token_transaction" edge to the TokenTransaction entity.
func (touo *TokenOutputUpdateOne) ClearOutputSpentTokenTransaction() *TokenOutputUpdateOne {
	touo.mutation.ClearOutputSpentTokenTransaction()
	return touo
}

// ClearOutputSpentStartedTokenTransactions clears all "output_spent_started_token_transactions" edges to the TokenTransaction entity.
func (touo *TokenOutputUpdateOne) ClearOutputSpentStartedTokenTransactions() *TokenOutputUpdateOne {
	touo.mutation.ClearOutputSpentStartedTokenTransactions()
	return touo
}

// RemoveOutputSpentStartedTokenTransactionIDs removes the "output_spent_started_token_transactions" edge to TokenTransaction entities by IDs.
func (touo *TokenOutputUpdateOne) RemoveOutputSpentStartedTokenTransactionIDs(ids ...uuid.UUID) *TokenOutputUpdateOne {
	touo.mutation.RemoveOutputSpentStartedTokenTransactionIDs(ids...)
	return touo
}

// RemoveOutputSpentStartedTokenTransactions removes "output_spent_started_token_transactions" edges to TokenTransaction entities.
func (touo *TokenOutputUpdateOne) RemoveOutputSpentStartedTokenTransactions(t ...*TokenTransaction) *TokenOutputUpdateOne {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return touo.RemoveOutputSpentStartedTokenTransactionIDs(ids...)
}

// ClearTokenPartialRevocationSecretShares clears all "token_partial_revocation_secret_shares" edges to the TokenPartialRevocationSecretShare entity.
func (touo *TokenOutputUpdateOne) ClearTokenPartialRevocationSecretShares() *TokenOutputUpdateOne {
	touo.mutation.ClearTokenPartialRevocationSecretShares()
	return touo
}

// RemoveTokenPartialRevocationSecretShareIDs removes the "token_partial_revocation_secret_shares" edge to TokenPartialRevocationSecretShare entities by IDs.
func (touo *TokenOutputUpdateOne) RemoveTokenPartialRevocationSecretShareIDs(ids ...uuid.UUID) *TokenOutputUpdateOne {
	touo.mutation.RemoveTokenPartialRevocationSecretShareIDs(ids...)
	return touo
}

// RemoveTokenPartialRevocationSecretShares removes "token_partial_revocation_secret_shares" edges to TokenPartialRevocationSecretShare entities.
func (touo *TokenOutputUpdateOne) RemoveTokenPartialRevocationSecretShares(t ...*TokenPartialRevocationSecretShare) *TokenOutputUpdateOne {
	ids := make([]uuid.UUID, len(t))
	for i := range t {
		ids[i] = t[i].ID
	}
	return touo.RemoveTokenPartialRevocationSecretShareIDs(ids...)
}

// Where appends a list predicates to the TokenOutputUpdate builder.
func (touo *TokenOutputUpdateOne) Where(ps ...predicate.TokenOutput) *TokenOutputUpdateOne {
	touo.mutation.Where(ps...)
	return touo
}

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

// Save executes the query and returns the updated TokenOutput entity.
func (touo *TokenOutputUpdateOne) Save(ctx context.Context) (*TokenOutput, error) {
	if err := touo.defaults(); err != nil {
		return nil, err
	}
	return withHooks(ctx, touo.sqlSave, touo.mutation, touo.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (touo *TokenOutputUpdateOne) defaults() error {
	if _, ok := touo.mutation.UpdateTime(); !ok {
		if tokenoutput.UpdateDefaultUpdateTime == nil {
			return fmt.Errorf("ent: uninitialized tokenoutput.UpdateDefaultUpdateTime (forgotten import ent/runtime?)")
		}
		v := tokenoutput.UpdateDefaultUpdateTime()
		touo.mutation.SetUpdateTime(v)
	}
	return nil
}

// check runs all checks and user-defined validators on the builder.
func (touo *TokenOutputUpdateOne) check() error {
	if v, ok := touo.mutation.Status(); ok {
		if err := tokenoutput.StatusValidator(v); err != nil {
			return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "TokenOutput.status": %w`, err)}
		}
	}
	if v, ok := touo.mutation.Network(); ok {
		if err := tokenoutput.NetworkValidator(v); err != nil {
			return &ValidationError{Name: "network", err: fmt.Errorf(`ent: validator failed for field "TokenOutput.network": %w`, err)}
		}
	}
	if touo.mutation.RevocationKeyshareCleared() && len(touo.mutation.RevocationKeyshareIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TokenOutput.revocation_keyshare"`)
	}
	if touo.mutation.TokenCreateCleared() && len(touo.mutation.TokenCreateIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TokenOutput.token_create"`)
	}
	return nil
}

func (touo *TokenOutputUpdateOne) sqlSave(ctx context.Context) (_node *TokenOutput, err error) {
	if err := touo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(tokenoutput.Table, tokenoutput.Columns, sqlgraph.NewFieldSpec(tokenoutput.FieldID, field.TypeUUID))
	id, ok := touo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TokenOutput.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := touo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, tokenoutput.FieldID)
		for _, f := range fields {
			if !tokenoutput.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != tokenoutput.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := touo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := touo.mutation.UpdateTime(); ok {
		_spec.SetField(tokenoutput.FieldUpdateTime, field.TypeTime, value)
	}
	if value, ok := touo.mutation.Status(); ok {
		_spec.SetField(tokenoutput.FieldStatus, field.TypeEnum, value)
	}
	if touo.mutation.TokenPublicKeyCleared() {
		_spec.ClearField(tokenoutput.FieldTokenPublicKey, field.TypeBytes)
	}
	if value, ok := touo.mutation.SpentOwnershipSignature(); ok {
		_spec.SetField(tokenoutput.FieldSpentOwnershipSignature, field.TypeBytes, value)
	}
	if touo.mutation.SpentOwnershipSignatureCleared() {
		_spec.ClearField(tokenoutput.FieldSpentOwnershipSignature, field.TypeBytes)
	}
	if value, ok := touo.mutation.SpentOperatorSpecificOwnershipSignature(); ok {
		_spec.SetField(tokenoutput.FieldSpentOperatorSpecificOwnershipSignature, field.TypeBytes, value)
	}
	if touo.mutation.SpentOperatorSpecificOwnershipSignatureCleared() {
		_spec.ClearField(tokenoutput.FieldSpentOperatorSpecificOwnershipSignature, field.TypeBytes)
	}
	if value, ok := touo.mutation.SpentTransactionInputVout(); ok {
		_spec.SetField(tokenoutput.FieldSpentTransactionInputVout, field.TypeInt32, value)
	}
	if value, ok := touo.mutation.AddedSpentTransactionInputVout(); ok {
		_spec.AddField(tokenoutput.FieldSpentTransactionInputVout, field.TypeInt32, value)
	}
	if touo.mutation.SpentTransactionInputVoutCleared() {
		_spec.ClearField(tokenoutput.FieldSpentTransactionInputVout, field.TypeInt32)
	}
	if value, ok := touo.mutation.SpentRevocationSecret(); ok {
		_spec.SetField(tokenoutput.FieldSpentRevocationSecret, field.TypeBytes, value)
	}
	if touo.mutation.SpentRevocationSecretCleared() {
		_spec.ClearField(tokenoutput.FieldSpentRevocationSecret, field.TypeBytes)
	}
	if value, ok := touo.mutation.ConfirmedWithdrawBlockHash(); ok {
		_spec.SetField(tokenoutput.FieldConfirmedWithdrawBlockHash, field.TypeBytes, value)
	}
	if touo.mutation.ConfirmedWithdrawBlockHashCleared() {
		_spec.ClearField(tokenoutput.FieldConfirmedWithdrawBlockHash, field.TypeBytes)
	}
	if value, ok := touo.mutation.Network(); ok {
		_spec.SetField(tokenoutput.FieldNetwork, field.TypeEnum, value)
	}
	if touo.mutation.NetworkCleared() {
		_spec.ClearField(tokenoutput.FieldNetwork, field.TypeEnum)
	}
	if touo.mutation.OutputCreatedTokenTransactionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputCreatedTokenTransactionTable,
			Columns: []string{tokenoutput.OutputCreatedTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := touo.mutation.OutputCreatedTokenTransactionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputCreatedTokenTransactionTable,
			Columns: []string{tokenoutput.OutputCreatedTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if touo.mutation.OutputSpentTokenTransactionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputSpentTokenTransactionTable,
			Columns: []string{tokenoutput.OutputSpentTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := touo.mutation.OutputSpentTokenTransactionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   tokenoutput.OutputSpentTokenTransactionTable,
			Columns: []string{tokenoutput.OutputSpentTokenTransactionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if touo.mutation.OutputSpentStartedTokenTransactionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokenoutput.OutputSpentStartedTokenTransactionsTable,
			Columns: tokenoutput.OutputSpentStartedTokenTransactionsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := touo.mutation.RemovedOutputSpentStartedTokenTransactionsIDs(); len(nodes) > 0 && !touo.mutation.OutputSpentStartedTokenTransactionsCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokenoutput.OutputSpentStartedTokenTransactionsTable,
			Columns: tokenoutput.OutputSpentStartedTokenTransactionsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := touo.mutation.OutputSpentStartedTokenTransactionsIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2M,
			Inverse: false,
			Table:   tokenoutput.OutputSpentStartedTokenTransactionsTable,
			Columns: tokenoutput.OutputSpentStartedTokenTransactionsPrimaryKey,
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokentransaction.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if touo.mutation.TokenPartialRevocationSecretSharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokenoutput.TokenPartialRevocationSecretSharesTable,
			Columns: []string{tokenoutput.TokenPartialRevocationSecretSharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := touo.mutation.RemovedTokenPartialRevocationSecretSharesIDs(); len(nodes) > 0 && !touo.mutation.TokenPartialRevocationSecretSharesCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokenoutput.TokenPartialRevocationSecretSharesTable,
			Columns: []string{tokenoutput.TokenPartialRevocationSecretSharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := touo.mutation.TokenPartialRevocationSecretSharesIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   tokenoutput.TokenPartialRevocationSecretSharesTable,
			Columns: []string{tokenoutput.TokenPartialRevocationSecretSharesColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(tokenpartialrevocationsecretshare.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &TokenOutput{config: touo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, touo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{tokenoutput.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	touo.mutation.done = true
	return _node, nil
}
