// 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/so/ent/predicate"
	"github.com/lightsparkdev/spark/so/ent/transfer"
	"github.com/lightsparkdev/spark/so/ent/transferleaf"
	"github.com/lightsparkdev/spark/so/ent/treenode"
)

// TransferLeafUpdate is the builder for updating TransferLeaf entities.
type TransferLeafUpdate struct {
	config
	hooks    []Hook
	mutation *TransferLeafMutation
}

// Where appends a list predicates to the TransferLeafUpdate builder.
func (tlu *TransferLeafUpdate) Where(ps ...predicate.TransferLeaf) *TransferLeafUpdate {
	tlu.mutation.Where(ps...)
	return tlu
}

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

// SetSecretCipher sets the "secret_cipher" field.
func (tlu *TransferLeafUpdate) SetSecretCipher(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetSecretCipher(b)
	return tlu
}

// ClearSecretCipher clears the value of the "secret_cipher" field.
func (tlu *TransferLeafUpdate) ClearSecretCipher() *TransferLeafUpdate {
	tlu.mutation.ClearSecretCipher()
	return tlu
}

// SetSignature sets the "signature" field.
func (tlu *TransferLeafUpdate) SetSignature(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetSignature(b)
	return tlu
}

// ClearSignature clears the value of the "signature" field.
func (tlu *TransferLeafUpdate) ClearSignature() *TransferLeafUpdate {
	tlu.mutation.ClearSignature()
	return tlu
}

// SetIntermediateRefundTx sets the "intermediate_refund_tx" field.
func (tlu *TransferLeafUpdate) SetIntermediateRefundTx(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetIntermediateRefundTx(b)
	return tlu
}

// SetIntermediateDirectRefundTx sets the "intermediate_direct_refund_tx" field.
func (tlu *TransferLeafUpdate) SetIntermediateDirectRefundTx(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetIntermediateDirectRefundTx(b)
	return tlu
}

// ClearIntermediateDirectRefundTx clears the value of the "intermediate_direct_refund_tx" field.
func (tlu *TransferLeafUpdate) ClearIntermediateDirectRefundTx() *TransferLeafUpdate {
	tlu.mutation.ClearIntermediateDirectRefundTx()
	return tlu
}

// SetIntermediateDirectFromCpfpRefundTx sets the "intermediate_direct_from_cpfp_refund_tx" field.
func (tlu *TransferLeafUpdate) SetIntermediateDirectFromCpfpRefundTx(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetIntermediateDirectFromCpfpRefundTx(b)
	return tlu
}

// ClearIntermediateDirectFromCpfpRefundTx clears the value of the "intermediate_direct_from_cpfp_refund_tx" field.
func (tlu *TransferLeafUpdate) ClearIntermediateDirectFromCpfpRefundTx() *TransferLeafUpdate {
	tlu.mutation.ClearIntermediateDirectFromCpfpRefundTx()
	return tlu
}

// SetKeyTweak sets the "key_tweak" field.
func (tlu *TransferLeafUpdate) SetKeyTweak(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetKeyTweak(b)
	return tlu
}

// ClearKeyTweak clears the value of the "key_tweak" field.
func (tlu *TransferLeafUpdate) ClearKeyTweak() *TransferLeafUpdate {
	tlu.mutation.ClearKeyTweak()
	return tlu
}

// SetSenderKeyTweakProof sets the "sender_key_tweak_proof" field.
func (tlu *TransferLeafUpdate) SetSenderKeyTweakProof(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetSenderKeyTweakProof(b)
	return tlu
}

// ClearSenderKeyTweakProof clears the value of the "sender_key_tweak_proof" field.
func (tlu *TransferLeafUpdate) ClearSenderKeyTweakProof() *TransferLeafUpdate {
	tlu.mutation.ClearSenderKeyTweakProof()
	return tlu
}

// SetReceiverKeyTweak sets the "receiver_key_tweak" field.
func (tlu *TransferLeafUpdate) SetReceiverKeyTweak(b []byte) *TransferLeafUpdate {
	tlu.mutation.SetReceiverKeyTweak(b)
	return tlu
}

// ClearReceiverKeyTweak clears the value of the "receiver_key_tweak" field.
func (tlu *TransferLeafUpdate) ClearReceiverKeyTweak() *TransferLeafUpdate {
	tlu.mutation.ClearReceiverKeyTweak()
	return tlu
}

// SetTransferID sets the "transfer" edge to the Transfer entity by ID.
func (tlu *TransferLeafUpdate) SetTransferID(id uuid.UUID) *TransferLeafUpdate {
	tlu.mutation.SetTransferID(id)
	return tlu
}

// SetTransfer sets the "transfer" edge to the Transfer entity.
func (tlu *TransferLeafUpdate) SetTransfer(t *Transfer) *TransferLeafUpdate {
	return tlu.SetTransferID(t.ID)
}

// SetLeafID sets the "leaf" edge to the TreeNode entity by ID.
func (tlu *TransferLeafUpdate) SetLeafID(id uuid.UUID) *TransferLeafUpdate {
	tlu.mutation.SetLeafID(id)
	return tlu
}

// SetLeaf sets the "leaf" edge to the TreeNode entity.
func (tlu *TransferLeafUpdate) SetLeaf(t *TreeNode) *TransferLeafUpdate {
	return tlu.SetLeafID(t.ID)
}

// Mutation returns the TransferLeafMutation object of the builder.
func (tlu *TransferLeafUpdate) Mutation() *TransferLeafMutation {
	return tlu.mutation
}

// ClearTransfer clears the "transfer" edge to the Transfer entity.
func (tlu *TransferLeafUpdate) ClearTransfer() *TransferLeafUpdate {
	tlu.mutation.ClearTransfer()
	return tlu
}

// ClearLeaf clears the "leaf" edge to the TreeNode entity.
func (tlu *TransferLeafUpdate) ClearLeaf() *TransferLeafUpdate {
	tlu.mutation.ClearLeaf()
	return tlu
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (tlu *TransferLeafUpdate) Save(ctx context.Context) (int, error) {
	tlu.defaults()
	return withHooks(ctx, tlu.sqlSave, tlu.mutation, tlu.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (tlu *TransferLeafUpdate) defaults() {
	if _, ok := tlu.mutation.UpdateTime(); !ok {
		v := transferleaf.UpdateDefaultUpdateTime()
		tlu.mutation.SetUpdateTime(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (tlu *TransferLeafUpdate) check() error {
	if v, ok := tlu.mutation.IntermediateRefundTx(); ok {
		if err := transferleaf.IntermediateRefundTxValidator(v); err != nil {
			return &ValidationError{Name: "intermediate_refund_tx", err: fmt.Errorf(`ent: validator failed for field "TransferLeaf.intermediate_refund_tx": %w`, err)}
		}
	}
	if tlu.mutation.TransferCleared() && len(tlu.mutation.TransferIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TransferLeaf.transfer"`)
	}
	if tlu.mutation.LeafCleared() && len(tlu.mutation.LeafIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TransferLeaf.leaf"`)
	}
	return nil
}

func (tlu *TransferLeafUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := tlu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(transferleaf.Table, transferleaf.Columns, sqlgraph.NewFieldSpec(transferleaf.FieldID, field.TypeUUID))
	if ps := tlu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := tlu.mutation.UpdateTime(); ok {
		_spec.SetField(transferleaf.FieldUpdateTime, field.TypeTime, value)
	}
	if value, ok := tlu.mutation.SecretCipher(); ok {
		_spec.SetField(transferleaf.FieldSecretCipher, field.TypeBytes, value)
	}
	if tlu.mutation.SecretCipherCleared() {
		_spec.ClearField(transferleaf.FieldSecretCipher, field.TypeBytes)
	}
	if value, ok := tlu.mutation.Signature(); ok {
		_spec.SetField(transferleaf.FieldSignature, field.TypeBytes, value)
	}
	if tlu.mutation.SignatureCleared() {
		_spec.ClearField(transferleaf.FieldSignature, field.TypeBytes)
	}
	if tlu.mutation.PreviousDirectRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldPreviousDirectRefundTx, field.TypeBytes)
	}
	if tlu.mutation.PreviousDirectFromCpfpRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldPreviousDirectFromCpfpRefundTx, field.TypeBytes)
	}
	if value, ok := tlu.mutation.IntermediateRefundTx(); ok {
		_spec.SetField(transferleaf.FieldIntermediateRefundTx, field.TypeBytes, value)
	}
	if value, ok := tlu.mutation.IntermediateDirectRefundTx(); ok {
		_spec.SetField(transferleaf.FieldIntermediateDirectRefundTx, field.TypeBytes, value)
	}
	if tlu.mutation.IntermediateDirectRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldIntermediateDirectRefundTx, field.TypeBytes)
	}
	if value, ok := tlu.mutation.IntermediateDirectFromCpfpRefundTx(); ok {
		_spec.SetField(transferleaf.FieldIntermediateDirectFromCpfpRefundTx, field.TypeBytes, value)
	}
	if tlu.mutation.IntermediateDirectFromCpfpRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldIntermediateDirectFromCpfpRefundTx, field.TypeBytes)
	}
	if value, ok := tlu.mutation.KeyTweak(); ok {
		_spec.SetField(transferleaf.FieldKeyTweak, field.TypeBytes, value)
	}
	if tlu.mutation.KeyTweakCleared() {
		_spec.ClearField(transferleaf.FieldKeyTweak, field.TypeBytes)
	}
	if value, ok := tlu.mutation.SenderKeyTweakProof(); ok {
		_spec.SetField(transferleaf.FieldSenderKeyTweakProof, field.TypeBytes, value)
	}
	if tlu.mutation.SenderKeyTweakProofCleared() {
		_spec.ClearField(transferleaf.FieldSenderKeyTweakProof, field.TypeBytes)
	}
	if value, ok := tlu.mutation.ReceiverKeyTweak(); ok {
		_spec.SetField(transferleaf.FieldReceiverKeyTweak, field.TypeBytes, value)
	}
	if tlu.mutation.ReceiverKeyTweakCleared() {
		_spec.ClearField(transferleaf.FieldReceiverKeyTweak, field.TypeBytes)
	}
	if tlu.mutation.TransferCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.TransferTable,
			Columns: []string{transferleaf.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tlu.mutation.TransferIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.TransferTable,
			Columns: []string{transferleaf.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if tlu.mutation.LeafCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.LeafTable,
			Columns: []string{transferleaf.LeafColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(treenode.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tlu.mutation.LeafIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.LeafTable,
			Columns: []string{transferleaf.LeafColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(treenode.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, tlu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{transferleaf.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	tlu.mutation.done = true
	return n, nil
}

// TransferLeafUpdateOne is the builder for updating a single TransferLeaf entity.
type TransferLeafUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *TransferLeafMutation
}

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

// SetSecretCipher sets the "secret_cipher" field.
func (tluo *TransferLeafUpdateOne) SetSecretCipher(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetSecretCipher(b)
	return tluo
}

// ClearSecretCipher clears the value of the "secret_cipher" field.
func (tluo *TransferLeafUpdateOne) ClearSecretCipher() *TransferLeafUpdateOne {
	tluo.mutation.ClearSecretCipher()
	return tluo
}

// SetSignature sets the "signature" field.
func (tluo *TransferLeafUpdateOne) SetSignature(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetSignature(b)
	return tluo
}

// ClearSignature clears the value of the "signature" field.
func (tluo *TransferLeafUpdateOne) ClearSignature() *TransferLeafUpdateOne {
	tluo.mutation.ClearSignature()
	return tluo
}

// SetIntermediateRefundTx sets the "intermediate_refund_tx" field.
func (tluo *TransferLeafUpdateOne) SetIntermediateRefundTx(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetIntermediateRefundTx(b)
	return tluo
}

// SetIntermediateDirectRefundTx sets the "intermediate_direct_refund_tx" field.
func (tluo *TransferLeafUpdateOne) SetIntermediateDirectRefundTx(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetIntermediateDirectRefundTx(b)
	return tluo
}

// ClearIntermediateDirectRefundTx clears the value of the "intermediate_direct_refund_tx" field.
func (tluo *TransferLeafUpdateOne) ClearIntermediateDirectRefundTx() *TransferLeafUpdateOne {
	tluo.mutation.ClearIntermediateDirectRefundTx()
	return tluo
}

// SetIntermediateDirectFromCpfpRefundTx sets the "intermediate_direct_from_cpfp_refund_tx" field.
func (tluo *TransferLeafUpdateOne) SetIntermediateDirectFromCpfpRefundTx(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetIntermediateDirectFromCpfpRefundTx(b)
	return tluo
}

// ClearIntermediateDirectFromCpfpRefundTx clears the value of the "intermediate_direct_from_cpfp_refund_tx" field.
func (tluo *TransferLeafUpdateOne) ClearIntermediateDirectFromCpfpRefundTx() *TransferLeafUpdateOne {
	tluo.mutation.ClearIntermediateDirectFromCpfpRefundTx()
	return tluo
}

// SetKeyTweak sets the "key_tweak" field.
func (tluo *TransferLeafUpdateOne) SetKeyTweak(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetKeyTweak(b)
	return tluo
}

// ClearKeyTweak clears the value of the "key_tweak" field.
func (tluo *TransferLeafUpdateOne) ClearKeyTweak() *TransferLeafUpdateOne {
	tluo.mutation.ClearKeyTweak()
	return tluo
}

// SetSenderKeyTweakProof sets the "sender_key_tweak_proof" field.
func (tluo *TransferLeafUpdateOne) SetSenderKeyTweakProof(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetSenderKeyTweakProof(b)
	return tluo
}

// ClearSenderKeyTweakProof clears the value of the "sender_key_tweak_proof" field.
func (tluo *TransferLeafUpdateOne) ClearSenderKeyTweakProof() *TransferLeafUpdateOne {
	tluo.mutation.ClearSenderKeyTweakProof()
	return tluo
}

// SetReceiverKeyTweak sets the "receiver_key_tweak" field.
func (tluo *TransferLeafUpdateOne) SetReceiverKeyTweak(b []byte) *TransferLeafUpdateOne {
	tluo.mutation.SetReceiverKeyTweak(b)
	return tluo
}

// ClearReceiverKeyTweak clears the value of the "receiver_key_tweak" field.
func (tluo *TransferLeafUpdateOne) ClearReceiverKeyTweak() *TransferLeafUpdateOne {
	tluo.mutation.ClearReceiverKeyTweak()
	return tluo
}

// SetTransferID sets the "transfer" edge to the Transfer entity by ID.
func (tluo *TransferLeafUpdateOne) SetTransferID(id uuid.UUID) *TransferLeafUpdateOne {
	tluo.mutation.SetTransferID(id)
	return tluo
}

// SetTransfer sets the "transfer" edge to the Transfer entity.
func (tluo *TransferLeafUpdateOne) SetTransfer(t *Transfer) *TransferLeafUpdateOne {
	return tluo.SetTransferID(t.ID)
}

// SetLeafID sets the "leaf" edge to the TreeNode entity by ID.
func (tluo *TransferLeafUpdateOne) SetLeafID(id uuid.UUID) *TransferLeafUpdateOne {
	tluo.mutation.SetLeafID(id)
	return tluo
}

// SetLeaf sets the "leaf" edge to the TreeNode entity.
func (tluo *TransferLeafUpdateOne) SetLeaf(t *TreeNode) *TransferLeafUpdateOne {
	return tluo.SetLeafID(t.ID)
}

// Mutation returns the TransferLeafMutation object of the builder.
func (tluo *TransferLeafUpdateOne) Mutation() *TransferLeafMutation {
	return tluo.mutation
}

// ClearTransfer clears the "transfer" edge to the Transfer entity.
func (tluo *TransferLeafUpdateOne) ClearTransfer() *TransferLeafUpdateOne {
	tluo.mutation.ClearTransfer()
	return tluo
}

// ClearLeaf clears the "leaf" edge to the TreeNode entity.
func (tluo *TransferLeafUpdateOne) ClearLeaf() *TransferLeafUpdateOne {
	tluo.mutation.ClearLeaf()
	return tluo
}

// Where appends a list predicates to the TransferLeafUpdate builder.
func (tluo *TransferLeafUpdateOne) Where(ps ...predicate.TransferLeaf) *TransferLeafUpdateOne {
	tluo.mutation.Where(ps...)
	return tluo
}

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

// Save executes the query and returns the updated TransferLeaf entity.
func (tluo *TransferLeafUpdateOne) Save(ctx context.Context) (*TransferLeaf, error) {
	tluo.defaults()
	return withHooks(ctx, tluo.sqlSave, tluo.mutation, tluo.hooks)
}

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

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

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

// defaults sets the default values of the builder before save.
func (tluo *TransferLeafUpdateOne) defaults() {
	if _, ok := tluo.mutation.UpdateTime(); !ok {
		v := transferleaf.UpdateDefaultUpdateTime()
		tluo.mutation.SetUpdateTime(v)
	}
}

// check runs all checks and user-defined validators on the builder.
func (tluo *TransferLeafUpdateOne) check() error {
	if v, ok := tluo.mutation.IntermediateRefundTx(); ok {
		if err := transferleaf.IntermediateRefundTxValidator(v); err != nil {
			return &ValidationError{Name: "intermediate_refund_tx", err: fmt.Errorf(`ent: validator failed for field "TransferLeaf.intermediate_refund_tx": %w`, err)}
		}
	}
	if tluo.mutation.TransferCleared() && len(tluo.mutation.TransferIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TransferLeaf.transfer"`)
	}
	if tluo.mutation.LeafCleared() && len(tluo.mutation.LeafIDs()) > 0 {
		return errors.New(`ent: clearing a required unique edge "TransferLeaf.leaf"`)
	}
	return nil
}

func (tluo *TransferLeafUpdateOne) sqlSave(ctx context.Context) (_node *TransferLeaf, err error) {
	if err := tluo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(transferleaf.Table, transferleaf.Columns, sqlgraph.NewFieldSpec(transferleaf.FieldID, field.TypeUUID))
	id, ok := tluo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TransferLeaf.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := tluo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, transferleaf.FieldID)
		for _, f := range fields {
			if !transferleaf.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != transferleaf.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := tluo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := tluo.mutation.UpdateTime(); ok {
		_spec.SetField(transferleaf.FieldUpdateTime, field.TypeTime, value)
	}
	if value, ok := tluo.mutation.SecretCipher(); ok {
		_spec.SetField(transferleaf.FieldSecretCipher, field.TypeBytes, value)
	}
	if tluo.mutation.SecretCipherCleared() {
		_spec.ClearField(transferleaf.FieldSecretCipher, field.TypeBytes)
	}
	if value, ok := tluo.mutation.Signature(); ok {
		_spec.SetField(transferleaf.FieldSignature, field.TypeBytes, value)
	}
	if tluo.mutation.SignatureCleared() {
		_spec.ClearField(transferleaf.FieldSignature, field.TypeBytes)
	}
	if tluo.mutation.PreviousDirectRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldPreviousDirectRefundTx, field.TypeBytes)
	}
	if tluo.mutation.PreviousDirectFromCpfpRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldPreviousDirectFromCpfpRefundTx, field.TypeBytes)
	}
	if value, ok := tluo.mutation.IntermediateRefundTx(); ok {
		_spec.SetField(transferleaf.FieldIntermediateRefundTx, field.TypeBytes, value)
	}
	if value, ok := tluo.mutation.IntermediateDirectRefundTx(); ok {
		_spec.SetField(transferleaf.FieldIntermediateDirectRefundTx, field.TypeBytes, value)
	}
	if tluo.mutation.IntermediateDirectRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldIntermediateDirectRefundTx, field.TypeBytes)
	}
	if value, ok := tluo.mutation.IntermediateDirectFromCpfpRefundTx(); ok {
		_spec.SetField(transferleaf.FieldIntermediateDirectFromCpfpRefundTx, field.TypeBytes, value)
	}
	if tluo.mutation.IntermediateDirectFromCpfpRefundTxCleared() {
		_spec.ClearField(transferleaf.FieldIntermediateDirectFromCpfpRefundTx, field.TypeBytes)
	}
	if value, ok := tluo.mutation.KeyTweak(); ok {
		_spec.SetField(transferleaf.FieldKeyTweak, field.TypeBytes, value)
	}
	if tluo.mutation.KeyTweakCleared() {
		_spec.ClearField(transferleaf.FieldKeyTweak, field.TypeBytes)
	}
	if value, ok := tluo.mutation.SenderKeyTweakProof(); ok {
		_spec.SetField(transferleaf.FieldSenderKeyTweakProof, field.TypeBytes, value)
	}
	if tluo.mutation.SenderKeyTweakProofCleared() {
		_spec.ClearField(transferleaf.FieldSenderKeyTweakProof, field.TypeBytes)
	}
	if value, ok := tluo.mutation.ReceiverKeyTweak(); ok {
		_spec.SetField(transferleaf.FieldReceiverKeyTweak, field.TypeBytes, value)
	}
	if tluo.mutation.ReceiverKeyTweakCleared() {
		_spec.ClearField(transferleaf.FieldReceiverKeyTweak, field.TypeBytes)
	}
	if tluo.mutation.TransferCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.TransferTable,
			Columns: []string{transferleaf.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tluo.mutation.TransferIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.TransferTable,
			Columns: []string{transferleaf.TransferColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(transfer.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if tluo.mutation.LeafCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.LeafTable,
			Columns: []string{transferleaf.LeafColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(treenode.FieldID, field.TypeUUID),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := tluo.mutation.LeafIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   transferleaf.LeafTable,
			Columns: []string{transferleaf.LeafColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(treenode.FieldID, field.TypeUUID),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &TransferLeaf{config: tluo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, tluo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{transferleaf.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	tluo.mutation.done = true
	return _node, nil
}
