// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"github.com/google/uuid"
	"github.com/lightsparkdev/spark/so/ent/transfer"
	"github.com/lightsparkdev/spark/so/ent/transferleaf"
	"github.com/lightsparkdev/spark/so/ent/treenode"
)

// TransferLeaf is the model entity for the TransferLeaf schema.
type TransferLeaf struct {
	config `json:"-"`
	// ID of the ent.
	ID uuid.UUID `json:"id,omitempty"`
	// CreateTime holds the value of the "create_time" field.
	CreateTime time.Time `json:"create_time,omitempty"`
	// UpdateTime holds the value of the "update_time" field.
	UpdateTime time.Time `json:"update_time,omitempty"`
	// SecretCipher holds the value of the "secret_cipher" field.
	SecretCipher []byte `json:"secret_cipher,omitempty"`
	// Signature holds the value of the "signature" field.
	Signature []byte `json:"signature,omitempty"`
	// PreviousRefundTx holds the value of the "previous_refund_tx" field.
	PreviousRefundTx []byte `json:"previous_refund_tx,omitempty"`
	// PreviousDirectRefundTx holds the value of the "previous_direct_refund_tx" field.
	PreviousDirectRefundTx []byte `json:"previous_direct_refund_tx,omitempty"`
	// PreviousDirectFromCpfpRefundTx holds the value of the "previous_direct_from_cpfp_refund_tx" field.
	PreviousDirectFromCpfpRefundTx []byte `json:"previous_direct_from_cpfp_refund_tx,omitempty"`
	// IntermediateRefundTx holds the value of the "intermediate_refund_tx" field.
	IntermediateRefundTx []byte `json:"intermediate_refund_tx,omitempty"`
	// IntermediateDirectRefundTx holds the value of the "intermediate_direct_refund_tx" field.
	IntermediateDirectRefundTx []byte `json:"intermediate_direct_refund_tx,omitempty"`
	// IntermediateDirectFromCpfpRefundTx holds the value of the "intermediate_direct_from_cpfp_refund_tx" field.
	IntermediateDirectFromCpfpRefundTx []byte `json:"intermediate_direct_from_cpfp_refund_tx,omitempty"`
	// KeyTweak holds the value of the "key_tweak" field.
	KeyTweak []byte `json:"key_tweak,omitempty"`
	// SenderKeyTweakProof holds the value of the "sender_key_tweak_proof" field.
	SenderKeyTweakProof []byte `json:"sender_key_tweak_proof,omitempty"`
	// ReceiverKeyTweak holds the value of the "receiver_key_tweak" field.
	ReceiverKeyTweak []byte `json:"receiver_key_tweak,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the TransferLeafQuery when eager-loading is set.
	Edges                  TransferLeafEdges `json:"edges"`
	transfer_leaf_transfer *uuid.UUID
	transfer_leaf_leaf     *uuid.UUID
	selectValues           sql.SelectValues
}

// TransferLeafEdges holds the relations/edges for other nodes in the graph.
type TransferLeafEdges struct {
	// Transfer holds the value of the transfer edge.
	Transfer *Transfer `json:"transfer,omitempty"`
	// Leaf holds the value of the leaf edge.
	Leaf *TreeNode `json:"leaf,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// TransferOrErr returns the Transfer value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TransferLeafEdges) TransferOrErr() (*Transfer, error) {
	if e.Transfer != nil {
		return e.Transfer, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: transfer.Label}
	}
	return nil, &NotLoadedError{edge: "transfer"}
}

// LeafOrErr returns the Leaf value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e TransferLeafEdges) LeafOrErr() (*TreeNode, error) {
	if e.Leaf != nil {
		return e.Leaf, nil
	} else if e.loadedTypes[1] {
		return nil, &NotFoundError{label: treenode.Label}
	}
	return nil, &NotLoadedError{edge: "leaf"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*TransferLeaf) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case transferleaf.FieldSecretCipher, transferleaf.FieldSignature, transferleaf.FieldPreviousRefundTx, transferleaf.FieldPreviousDirectRefundTx, transferleaf.FieldPreviousDirectFromCpfpRefundTx, transferleaf.FieldIntermediateRefundTx, transferleaf.FieldIntermediateDirectRefundTx, transferleaf.FieldIntermediateDirectFromCpfpRefundTx, transferleaf.FieldKeyTweak, transferleaf.FieldSenderKeyTweakProof, transferleaf.FieldReceiverKeyTweak:
			values[i] = new([]byte)
		case transferleaf.FieldCreateTime, transferleaf.FieldUpdateTime:
			values[i] = new(sql.NullTime)
		case transferleaf.FieldID:
			values[i] = new(uuid.UUID)
		case transferleaf.ForeignKeys[0]: // transfer_leaf_transfer
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		case transferleaf.ForeignKeys[1]: // transfer_leaf_leaf
			values[i] = &sql.NullScanner{S: new(uuid.UUID)}
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the TransferLeaf fields.
func (tl *TransferLeaf) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case transferleaf.FieldID:
			if value, ok := values[i].(*uuid.UUID); !ok {
				return fmt.Errorf("unexpected type %T for field id", values[i])
			} else if value != nil {
				tl.ID = *value
			}
		case transferleaf.FieldCreateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field create_time", values[i])
			} else if value.Valid {
				tl.CreateTime = value.Time
			}
		case transferleaf.FieldUpdateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field update_time", values[i])
			} else if value.Valid {
				tl.UpdateTime = value.Time
			}
		case transferleaf.FieldSecretCipher:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field secret_cipher", values[i])
			} else if value != nil {
				tl.SecretCipher = *value
			}
		case transferleaf.FieldSignature:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field signature", values[i])
			} else if value != nil {
				tl.Signature = *value
			}
		case transferleaf.FieldPreviousRefundTx:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field previous_refund_tx", values[i])
			} else if value != nil {
				tl.PreviousRefundTx = *value
			}
		case transferleaf.FieldPreviousDirectRefundTx:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field previous_direct_refund_tx", values[i])
			} else if value != nil {
				tl.PreviousDirectRefundTx = *value
			}
		case transferleaf.FieldPreviousDirectFromCpfpRefundTx:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field previous_direct_from_cpfp_refund_tx", values[i])
			} else if value != nil {
				tl.PreviousDirectFromCpfpRefundTx = *value
			}
		case transferleaf.FieldIntermediateRefundTx:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field intermediate_refund_tx", values[i])
			} else if value != nil {
				tl.IntermediateRefundTx = *value
			}
		case transferleaf.FieldIntermediateDirectRefundTx:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field intermediate_direct_refund_tx", values[i])
			} else if value != nil {
				tl.IntermediateDirectRefundTx = *value
			}
		case transferleaf.FieldIntermediateDirectFromCpfpRefundTx:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field intermediate_direct_from_cpfp_refund_tx", values[i])
			} else if value != nil {
				tl.IntermediateDirectFromCpfpRefundTx = *value
			}
		case transferleaf.FieldKeyTweak:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field key_tweak", values[i])
			} else if value != nil {
				tl.KeyTweak = *value
			}
		case transferleaf.FieldSenderKeyTweakProof:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field sender_key_tweak_proof", values[i])
			} else if value != nil {
				tl.SenderKeyTweakProof = *value
			}
		case transferleaf.FieldReceiverKeyTweak:
			if value, ok := values[i].(*[]byte); !ok {
				return fmt.Errorf("unexpected type %T for field receiver_key_tweak", values[i])
			} else if value != nil {
				tl.ReceiverKeyTweak = *value
			}
		case transferleaf.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field transfer_leaf_transfer", values[i])
			} else if value.Valid {
				tl.transfer_leaf_transfer = new(uuid.UUID)
				*tl.transfer_leaf_transfer = *value.S.(*uuid.UUID)
			}
		case transferleaf.ForeignKeys[1]:
			if value, ok := values[i].(*sql.NullScanner); !ok {
				return fmt.Errorf("unexpected type %T for field transfer_leaf_leaf", values[i])
			} else if value.Valid {
				tl.transfer_leaf_leaf = new(uuid.UUID)
				*tl.transfer_leaf_leaf = *value.S.(*uuid.UUID)
			}
		default:
			tl.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the TransferLeaf.
// This includes values selected through modifiers, order, etc.
func (tl *TransferLeaf) Value(name string) (ent.Value, error) {
	return tl.selectValues.Get(name)
}

// QueryTransfer queries the "transfer" edge of the TransferLeaf entity.
func (tl *TransferLeaf) QueryTransfer() *TransferQuery {
	return NewTransferLeafClient(tl.config).QueryTransfer(tl)
}

// QueryLeaf queries the "leaf" edge of the TransferLeaf entity.
func (tl *TransferLeaf) QueryLeaf() *TreeNodeQuery {
	return NewTransferLeafClient(tl.config).QueryLeaf(tl)
}

// Update returns a builder for updating this TransferLeaf.
// Note that you need to call TransferLeaf.Unwrap() before calling this method if this TransferLeaf
// was returned from a transaction, and the transaction was committed or rolled back.
func (tl *TransferLeaf) Update() *TransferLeafUpdateOne {
	return NewTransferLeafClient(tl.config).UpdateOne(tl)
}

// Unwrap unwraps the TransferLeaf entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (tl *TransferLeaf) Unwrap() *TransferLeaf {
	_tx, ok := tl.config.driver.(*txDriver)
	if !ok {
		panic("ent: TransferLeaf is not a transactional entity")
	}
	tl.config.driver = _tx.drv
	return tl
}

// String implements the fmt.Stringer.
func (tl *TransferLeaf) String() string {
	var builder strings.Builder
	builder.WriteString("TransferLeaf(")
	builder.WriteString(fmt.Sprintf("id=%v, ", tl.ID))
	builder.WriteString("create_time=")
	builder.WriteString(tl.CreateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("update_time=")
	builder.WriteString(tl.UpdateTime.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("secret_cipher=")
	builder.WriteString(fmt.Sprintf("%v", tl.SecretCipher))
	builder.WriteString(", ")
	builder.WriteString("signature=")
	builder.WriteString(fmt.Sprintf("%v", tl.Signature))
	builder.WriteString(", ")
	builder.WriteString("previous_refund_tx=")
	builder.WriteString(fmt.Sprintf("%v", tl.PreviousRefundTx))
	builder.WriteString(", ")
	builder.WriteString("previous_direct_refund_tx=")
	builder.WriteString(fmt.Sprintf("%v", tl.PreviousDirectRefundTx))
	builder.WriteString(", ")
	builder.WriteString("previous_direct_from_cpfp_refund_tx=")
	builder.WriteString(fmt.Sprintf("%v", tl.PreviousDirectFromCpfpRefundTx))
	builder.WriteString(", ")
	builder.WriteString("intermediate_refund_tx=")
	builder.WriteString(fmt.Sprintf("%v", tl.IntermediateRefundTx))
	builder.WriteString(", ")
	builder.WriteString("intermediate_direct_refund_tx=")
	builder.WriteString(fmt.Sprintf("%v", tl.IntermediateDirectRefundTx))
	builder.WriteString(", ")
	builder.WriteString("intermediate_direct_from_cpfp_refund_tx=")
	builder.WriteString(fmt.Sprintf("%v", tl.IntermediateDirectFromCpfpRefundTx))
	builder.WriteString(", ")
	builder.WriteString("key_tweak=")
	builder.WriteString(fmt.Sprintf("%v", tl.KeyTweak))
	builder.WriteString(", ")
	builder.WriteString("sender_key_tweak_proof=")
	builder.WriteString(fmt.Sprintf("%v", tl.SenderKeyTweakProof))
	builder.WriteString(", ")
	builder.WriteString("receiver_key_tweak=")
	builder.WriteString(fmt.Sprintf("%v", tl.ReceiverKeyTweak))
	builder.WriteByte(')')
	return builder.String()
}

// TransferLeafs is a parsable slice of TransferLeaf.
type TransferLeafs []*TransferLeaf
