// Code generated by ent, DO NOT EDIT.

package preimagerequest

import (
	"fmt"
	"time"

	"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 preimagerequest type in the database.
	Label = "preimage_request"
	// 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"
	// FieldPaymentHash holds the string denoting the payment_hash field in the database.
	FieldPaymentHash = "payment_hash"
	// FieldStatus holds the string denoting the status field in the database.
	FieldStatus = "status"
	// FieldReceiverIdentityPubkey holds the string denoting the receiver_identity_pubkey field in the database.
	FieldReceiverIdentityPubkey = "receiver_identity_pubkey"
	// FieldPreimage holds the string denoting the preimage field in the database.
	FieldPreimage = "preimage"
	// EdgeTransactions holds the string denoting the transactions edge name in mutations.
	EdgeTransactions = "transactions"
	// EdgePreimageShares holds the string denoting the preimage_shares edge name in mutations.
	EdgePreimageShares = "preimage_shares"
	// EdgeTransfers holds the string denoting the transfers edge name in mutations.
	EdgeTransfers = "transfers"
	// Table holds the table name of the preimagerequest in the database.
	Table = "preimage_requests"
	// TransactionsTable is the table that holds the transactions relation/edge.
	TransactionsTable = "user_signed_transactions"
	// TransactionsInverseTable is the table name for the UserSignedTransaction entity.
	// It exists in this package in order to avoid circular dependency with the "usersignedtransaction" package.
	TransactionsInverseTable = "user_signed_transactions"
	// TransactionsColumn is the table column denoting the transactions relation/edge.
	TransactionsColumn = "user_signed_transaction_preimage_request"
	// PreimageSharesTable is the table that holds the preimage_shares relation/edge.
	PreimageSharesTable = "preimage_shares"
	// PreimageSharesInverseTable is the table name for the PreimageShare entity.
	// It exists in this package in order to avoid circular dependency with the "preimageshare" package.
	PreimageSharesInverseTable = "preimage_shares"
	// PreimageSharesColumn is the table column denoting the preimage_shares relation/edge.
	PreimageSharesColumn = "preimage_request_preimage_shares"
	// TransfersTable is the table that holds the transfers relation/edge.
	TransfersTable = "preimage_requests"
	// TransfersInverseTable is the table name for the Transfer entity.
	// It exists in this package in order to avoid circular dependency with the "transfer" package.
	TransfersInverseTable = "transfers"
	// TransfersColumn is the table column denoting the transfers relation/edge.
	TransfersColumn = "preimage_request_transfers"
)

// Columns holds all SQL columns for preimagerequest fields.
var Columns = []string{
	FieldID,
	FieldCreateTime,
	FieldUpdateTime,
	FieldPaymentHash,
	FieldStatus,
	FieldReceiverIdentityPubkey,
	FieldPreimage,
}

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

// 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
}

var (
	// 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
	// PaymentHashValidator is a validator for the "payment_hash" field. It is called by the builders before save.
	PaymentHashValidator 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.PreimageRequestStatus) error {
	switch s {
	case "WAITING_FOR_PREIMAGE", "PREIMAGE_SHARED", "RETURNED":
		return nil
	default:
		return fmt.Errorf("preimagerequest: invalid enum value for status field: %q", s)
	}
}

// OrderOption defines the ordering options for the PreimageRequest 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()
}

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

// ByTransactionsCount orders the results by transactions count.
func ByTransactionsCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newTransactionsStep(), opts...)
	}
}

// ByTransactions orders the results by transactions terms.
func ByTransactions(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newTransactionsStep(), append([]sql.OrderTerm{term}, terms...)...)
	}
}

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

// ByTransfersField orders the results by transfers field.
func ByTransfersField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newTransfersStep(), sql.OrderByField(field, opts...))
	}
}
func newTransactionsStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(TransactionsInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.O2M, true, TransactionsTable, TransactionsColumn),
	)
}
func newPreimageSharesStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(PreimageSharesInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.O2O, false, PreimageSharesTable, PreimageSharesColumn),
	)
}
func newTransfersStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(TransfersInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, false, TransfersTable, TransfersColumn),
	)
}
