// Code generated by ent, DO NOT EDIT.

package treenode

import (
	"fmt"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"github.com/google/uuid"
	"github.com/lightsparkdev/spark/so/ent/schema/schematype"
)

const (
	// Label holds the string label denoting the treenode type in the database.
	Label = "tree_node"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldCreateTime holds the string denoting the create_time field in the database.
	FieldCreateTime = "create_time"
	// FieldUpdateTime holds the string denoting the update_time field in the database.
	FieldUpdateTime = "update_time"
	// FieldValue holds the string denoting the value field in the database.
	FieldValue = "value"
	// FieldStatus holds the string denoting the status field in the database.
	FieldStatus = "status"
	// FieldVerifyingPubkey holds the string denoting the verifying_pubkey field in the database.
	FieldVerifyingPubkey = "verifying_pubkey"
	// FieldOwnerIdentityPubkey holds the string denoting the owner_identity_pubkey field in the database.
	FieldOwnerIdentityPubkey = "owner_identity_pubkey"
	// FieldOwnerSigningPubkey holds the string denoting the owner_signing_pubkey field in the database.
	FieldOwnerSigningPubkey = "owner_signing_pubkey"
	// FieldVout holds the string denoting the vout field in the database.
	FieldVout = "vout"
	// FieldNodeConfirmationHeight holds the string denoting the node_confirmation_height field in the database.
	FieldNodeConfirmationHeight = "node_confirmation_height"
	// FieldRefundConfirmationHeight holds the string denoting the refund_confirmation_height field in the database.
	FieldRefundConfirmationHeight = "refund_confirmation_height"
	// FieldRawTx holds the string denoting the raw_tx field in the database.
	FieldRawTx = "raw_tx"
	// FieldDirectTx holds the string denoting the direct_tx field in the database.
	FieldDirectTx = "direct_tx"
	// FieldDirectFromCpfpRefundTx holds the string denoting the direct_from_cpfp_refund_tx field in the database.
	FieldDirectFromCpfpRefundTx = "direct_from_cpfp_refund_tx"
	// FieldRawTxid holds the string denoting the raw_txid field in the database.
	FieldRawTxid = "raw_txid"
	// FieldDirectTxid holds the string denoting the direct_txid field in the database.
	FieldDirectTxid = "direct_txid"
	// FieldDirectFromCpfpRefundTxid holds the string denoting the direct_from_cpfp_refund_txid field in the database.
	FieldDirectFromCpfpRefundTxid = "direct_from_cpfp_refund_txid"
	// FieldRawRefundTx holds the string denoting the raw_refund_tx field in the database.
	FieldRawRefundTx = "raw_refund_tx"
	// FieldDirectRefundTx holds the string denoting the direct_refund_tx field in the database.
	FieldDirectRefundTx = "direct_refund_tx"
	// FieldRawRefundTxid holds the string denoting the raw_refund_txid field in the database.
	FieldRawRefundTxid = "raw_refund_txid"
	// FieldDirectRefundTxid holds the string denoting the direct_refund_txid field in the database.
	FieldDirectRefundTxid = "direct_refund_txid"
	// EdgeTree holds the string denoting the tree edge name in mutations.
	EdgeTree = "tree"
	// EdgeParent holds the string denoting the parent edge name in mutations.
	EdgeParent = "parent"
	// EdgeSigningKeyshare holds the string denoting the signing_keyshare edge name in mutations.
	EdgeSigningKeyshare = "signing_keyshare"
	// EdgeChildren holds the string denoting the children edge name in mutations.
	EdgeChildren = "children"
	// Table holds the table name of the treenode in the database.
	Table = "tree_nodes"
	// TreeTable is the table that holds the tree relation/edge.
	TreeTable = "tree_nodes"
	// TreeInverseTable is the table name for the Tree entity.
	// It exists in this package in order to avoid circular dependency with the "tree" package.
	TreeInverseTable = "trees"
	// TreeColumn is the table column denoting the tree relation/edge.
	TreeColumn = "tree_node_tree"
	// ParentTable is the table that holds the parent relation/edge.
	ParentTable = "tree_nodes"
	// ParentColumn is the table column denoting the parent relation/edge.
	ParentColumn = "tree_node_parent"
	// SigningKeyshareTable is the table that holds the signing_keyshare relation/edge.
	SigningKeyshareTable = "tree_nodes"
	// SigningKeyshareInverseTable is the table name for the SigningKeyshare entity.
	// It exists in this package in order to avoid circular dependency with the "signingkeyshare" package.
	SigningKeyshareInverseTable = "signing_keyshares"
	// SigningKeyshareColumn is the table column denoting the signing_keyshare relation/edge.
	SigningKeyshareColumn = "tree_node_signing_keyshare"
	// ChildrenTable is the table that holds the children relation/edge.
	ChildrenTable = "tree_nodes"
	// ChildrenColumn is the table column denoting the children relation/edge.
	ChildrenColumn = "tree_node_parent"
)

// Columns holds all SQL columns for treenode fields.
var Columns = []string{
	FieldID,
	FieldCreateTime,
	FieldUpdateTime,
	FieldValue,
	FieldStatus,
	FieldVerifyingPubkey,
	FieldOwnerIdentityPubkey,
	FieldOwnerSigningPubkey,
	FieldVout,
	FieldNodeConfirmationHeight,
	FieldRefundConfirmationHeight,
	FieldRawTx,
	FieldDirectTx,
	FieldDirectFromCpfpRefundTx,
	FieldRawTxid,
	FieldDirectTxid,
	FieldDirectFromCpfpRefundTxid,
	FieldRawRefundTx,
	FieldDirectRefundTx,
	FieldRawRefundTxid,
	FieldDirectRefundTxid,
}

// ForeignKeys holds the SQL foreign-keys that are owned by the "tree_nodes"
// table and are not defined as standalone fields in the schema.
var ForeignKeys = []string{
	"tree_node_tree",
	"tree_node_parent",
	"tree_node_signing_keyshare",
}

// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
	for i := range Columns {
		if column == Columns[i] {
			return true
		}
	}
	for i := range ForeignKeys {
		if column == ForeignKeys[i] {
			return true
		}
	}
	return false
}

// Note that the variables below are initialized by the runtime
// package on the initialization of the application. Therefore,
// it should be imported in the main as follows:
//
//	import _ "github.com/lightsparkdev/spark/so/ent/runtime"
var (
	Hooks [2]ent.Hook
	// DefaultCreateTime holds the default value on creation for the "create_time" field.
	DefaultCreateTime func() time.Time
	// DefaultUpdateTime holds the default value on creation for the "update_time" field.
	DefaultUpdateTime func() time.Time
	// UpdateDefaultUpdateTime holds the default value on update for the "update_time" field.
	UpdateDefaultUpdateTime func() time.Time
	// RawTxValidator is a validator for the "raw_tx" field. It is called by the builders before save.
	RawTxValidator func([]byte) error
	// DefaultID holds the default value on creation for the "id" field.
	DefaultID func() uuid.UUID
)

// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
func StatusValidator(s schematype.TreeNodeStatus) error {
	switch s {
	case "CREATING", "AVAILABLE", "FROZEN_BY_ISSUER", "TRANSFER_LOCKED", "SPLIT_LOCKED", "SPLITTED", "AGGREGATED", "ON_CHAIN", "AGGREGATE_LOCK", "EXITED", "INVESTIGATION", "LOST", "REIMBURSED":
		return nil
	default:
		return fmt.Errorf("treenode: invalid enum value for status field: %q", s)
	}
}

// OrderOption defines the ordering options for the TreeNode queries.
type OrderOption func(*sql.Selector)

// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldID, opts...).ToFunc()
}

// ByCreateTime orders the results by the create_time field.
func ByCreateTime(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldCreateTime, opts...).ToFunc()
}

// ByUpdateTime orders the results by the update_time field.
func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldUpdateTime, opts...).ToFunc()
}

// ByValue orders the results by the value field.
func ByValue(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldValue, opts...).ToFunc()
}

// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldStatus, opts...).ToFunc()
}

// ByVout orders the results by the vout field.
func ByVout(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldVout, opts...).ToFunc()
}

// ByNodeConfirmationHeight orders the results by the node_confirmation_height field.
func ByNodeConfirmationHeight(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldNodeConfirmationHeight, opts...).ToFunc()
}

// ByRefundConfirmationHeight orders the results by the refund_confirmation_height field.
func ByRefundConfirmationHeight(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldRefundConfirmationHeight, opts...).ToFunc()
}

// ByTreeField orders the results by tree field.
func ByTreeField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newTreeStep(), sql.OrderByField(field, opts...))
	}
}

// ByParentField orders the results by parent field.
func ByParentField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newParentStep(), sql.OrderByField(field, opts...))
	}
}

// BySigningKeyshareField orders the results by signing_keyshare field.
func BySigningKeyshareField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newSigningKeyshareStep(), sql.OrderByField(field, opts...))
	}
}

// ByChildrenCount orders the results by children count.
func ByChildrenCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newChildrenStep(), opts...)
	}
}

// ByChildren orders the results by children terms.
func ByChildren(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newChildrenStep(), append([]sql.OrderTerm{term}, terms...)...)
	}
}
func newTreeStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(TreeInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, false, TreeTable, TreeColumn),
	)
}
func newParentStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(Table, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, false, ParentTable, ParentColumn),
	)
}
func newSigningKeyshareStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(SigningKeyshareInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, false, SigningKeyshareTable, SigningKeyshareColumn),
	)
}
func newChildrenStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(Table, FieldID),
		sqlgraph.Edge(sqlgraph.O2M, true, ChildrenTable, ChildrenColumn),
	)
}
