// Code generated by ent, DO NOT EDIT.

package intercept

import (
	"context"
	"fmt"

	"entgo.io/ent/dialect/sql"
	"github.com/lightsparkdev/spark/so/ent"
	"github.com/lightsparkdev/spark/so/ent/blockheight"
	"github.com/lightsparkdev/spark/so/ent/cooperativeexit"
	"github.com/lightsparkdev/spark/so/ent/depositaddress"
	"github.com/lightsparkdev/spark/so/ent/entitydkgkey"
	"github.com/lightsparkdev/spark/so/ent/gossip"
	"github.com/lightsparkdev/spark/so/ent/l1tokencreate"
	"github.com/lightsparkdev/spark/so/ent/paymentintent"
	"github.com/lightsparkdev/spark/so/ent/pendingsendtransfer"
	"github.com/lightsparkdev/spark/so/ent/predicate"
	"github.com/lightsparkdev/spark/so/ent/preimagerequest"
	"github.com/lightsparkdev/spark/so/ent/preimageshare"
	"github.com/lightsparkdev/spark/so/ent/signingcommitment"
	"github.com/lightsparkdev/spark/so/ent/signingkeyshare"
	"github.com/lightsparkdev/spark/so/ent/signingnonce"
	"github.com/lightsparkdev/spark/so/ent/sparkinvoice"
	"github.com/lightsparkdev/spark/so/ent/tokencreate"
	"github.com/lightsparkdev/spark/so/ent/tokenfreeze"
	"github.com/lightsparkdev/spark/so/ent/tokenmint"
	"github.com/lightsparkdev/spark/so/ent/tokenoutput"
	"github.com/lightsparkdev/spark/so/ent/tokenpartialrevocationsecretshare"
	"github.com/lightsparkdev/spark/so/ent/tokentransaction"
	"github.com/lightsparkdev/spark/so/ent/tokentransactionpeersignature"
	"github.com/lightsparkdev/spark/so/ent/transfer"
	"github.com/lightsparkdev/spark/so/ent/transferleaf"
	"github.com/lightsparkdev/spark/so/ent/tree"
	"github.com/lightsparkdev/spark/so/ent/treenode"
	"github.com/lightsparkdev/spark/so/ent/usersignedtransaction"
	"github.com/lightsparkdev/spark/so/ent/utxo"
	"github.com/lightsparkdev/spark/so/ent/utxoswap"
)

// The Query interface represents an operation that queries a graph.
// By using this interface, users can write generic code that manipulates
// query builders of different types.
type Query interface {
	// Type returns the string representation of the query type.
	Type() string
	// Limit the number of records to be returned by this query.
	Limit(int)
	// Offset to start from.
	Offset(int)
	// Unique configures the query builder to filter duplicate records.
	Unique(bool)
	// Order specifies how the records should be ordered.
	Order(...func(*sql.Selector))
	// WhereP appends storage-level predicates to the query builder. Using this method, users
	// can use type-assertion to append predicates that do not depend on any generated package.
	WhereP(...func(*sql.Selector))
}

// The Func type is an adapter that allows ordinary functions to be used as interceptors.
// Unlike traversal functions, interceptors are skipped during graph traversals. Note that the
// implementation of Func is different from the one defined in entgo.io/ent.InterceptFunc.
type Func func(context.Context, Query) error

// Intercept calls f(ctx, q) and then applied the next Querier.
func (f Func) Intercept(next ent.Querier) ent.Querier {
	return ent.QuerierFunc(func(ctx context.Context, q ent.Query) (ent.Value, error) {
		query, err := NewQuery(q)
		if err != nil {
			return nil, err
		}
		if err := f(ctx, query); err != nil {
			return nil, err
		}
		return next.Query(ctx, q)
	})
}

// The TraverseFunc type is an adapter to allow the use of ordinary function as Traverser.
// If f is a function with the appropriate signature, TraverseFunc(f) is a Traverser that calls f.
type TraverseFunc func(context.Context, Query) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseFunc) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
	query, err := NewQuery(q)
	if err != nil {
		return err
	}
	return f(ctx, query)
}

// The BlockHeightFunc type is an adapter to allow the use of ordinary function as a Querier.
type BlockHeightFunc func(context.Context, *ent.BlockHeightQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f BlockHeightFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.BlockHeightQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.BlockHeightQuery", q)
}

// The TraverseBlockHeight type is an adapter to allow the use of ordinary function as Traverser.
type TraverseBlockHeight func(context.Context, *ent.BlockHeightQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseBlockHeight) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseBlockHeight) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.BlockHeightQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.BlockHeightQuery", q)
}

// The CooperativeExitFunc type is an adapter to allow the use of ordinary function as a Querier.
type CooperativeExitFunc func(context.Context, *ent.CooperativeExitQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f CooperativeExitFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.CooperativeExitQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.CooperativeExitQuery", q)
}

// The TraverseCooperativeExit type is an adapter to allow the use of ordinary function as Traverser.
type TraverseCooperativeExit func(context.Context, *ent.CooperativeExitQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseCooperativeExit) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseCooperativeExit) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.CooperativeExitQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.CooperativeExitQuery", q)
}

// The DepositAddressFunc type is an adapter to allow the use of ordinary function as a Querier.
type DepositAddressFunc func(context.Context, *ent.DepositAddressQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f DepositAddressFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.DepositAddressQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.DepositAddressQuery", q)
}

// The TraverseDepositAddress type is an adapter to allow the use of ordinary function as Traverser.
type TraverseDepositAddress func(context.Context, *ent.DepositAddressQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseDepositAddress) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseDepositAddress) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.DepositAddressQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.DepositAddressQuery", q)
}

// The EntityDkgKeyFunc type is an adapter to allow the use of ordinary function as a Querier.
type EntityDkgKeyFunc func(context.Context, *ent.EntityDkgKeyQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f EntityDkgKeyFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.EntityDkgKeyQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.EntityDkgKeyQuery", q)
}

// The TraverseEntityDkgKey type is an adapter to allow the use of ordinary function as Traverser.
type TraverseEntityDkgKey func(context.Context, *ent.EntityDkgKeyQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseEntityDkgKey) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseEntityDkgKey) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.EntityDkgKeyQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.EntityDkgKeyQuery", q)
}

// The GossipFunc type is an adapter to allow the use of ordinary function as a Querier.
type GossipFunc func(context.Context, *ent.GossipQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f GossipFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.GossipQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.GossipQuery", q)
}

// The TraverseGossip type is an adapter to allow the use of ordinary function as Traverser.
type TraverseGossip func(context.Context, *ent.GossipQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseGossip) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseGossip) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.GossipQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.GossipQuery", q)
}

// The L1TokenCreateFunc type is an adapter to allow the use of ordinary function as a Querier.
type L1TokenCreateFunc func(context.Context, *ent.L1TokenCreateQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f L1TokenCreateFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.L1TokenCreateQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.L1TokenCreateQuery", q)
}

// The TraverseL1TokenCreate type is an adapter to allow the use of ordinary function as Traverser.
type TraverseL1TokenCreate func(context.Context, *ent.L1TokenCreateQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseL1TokenCreate) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseL1TokenCreate) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.L1TokenCreateQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.L1TokenCreateQuery", q)
}

// The PaymentIntentFunc type is an adapter to allow the use of ordinary function as a Querier.
type PaymentIntentFunc func(context.Context, *ent.PaymentIntentQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f PaymentIntentFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.PaymentIntentQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.PaymentIntentQuery", q)
}

// The TraversePaymentIntent type is an adapter to allow the use of ordinary function as Traverser.
type TraversePaymentIntent func(context.Context, *ent.PaymentIntentQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraversePaymentIntent) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraversePaymentIntent) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.PaymentIntentQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.PaymentIntentQuery", q)
}

// The PendingSendTransferFunc type is an adapter to allow the use of ordinary function as a Querier.
type PendingSendTransferFunc func(context.Context, *ent.PendingSendTransferQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f PendingSendTransferFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.PendingSendTransferQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.PendingSendTransferQuery", q)
}

// The TraversePendingSendTransfer type is an adapter to allow the use of ordinary function as Traverser.
type TraversePendingSendTransfer func(context.Context, *ent.PendingSendTransferQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraversePendingSendTransfer) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraversePendingSendTransfer) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.PendingSendTransferQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.PendingSendTransferQuery", q)
}

// The PreimageRequestFunc type is an adapter to allow the use of ordinary function as a Querier.
type PreimageRequestFunc func(context.Context, *ent.PreimageRequestQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f PreimageRequestFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.PreimageRequestQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.PreimageRequestQuery", q)
}

// The TraversePreimageRequest type is an adapter to allow the use of ordinary function as Traverser.
type TraversePreimageRequest func(context.Context, *ent.PreimageRequestQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraversePreimageRequest) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraversePreimageRequest) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.PreimageRequestQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.PreimageRequestQuery", q)
}

// The PreimageShareFunc type is an adapter to allow the use of ordinary function as a Querier.
type PreimageShareFunc func(context.Context, *ent.PreimageShareQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f PreimageShareFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.PreimageShareQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.PreimageShareQuery", q)
}

// The TraversePreimageShare type is an adapter to allow the use of ordinary function as Traverser.
type TraversePreimageShare func(context.Context, *ent.PreimageShareQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraversePreimageShare) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraversePreimageShare) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.PreimageShareQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.PreimageShareQuery", q)
}

// The SigningCommitmentFunc type is an adapter to allow the use of ordinary function as a Querier.
type SigningCommitmentFunc func(context.Context, *ent.SigningCommitmentQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f SigningCommitmentFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.SigningCommitmentQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.SigningCommitmentQuery", q)
}

// The TraverseSigningCommitment type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSigningCommitment func(context.Context, *ent.SigningCommitmentQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSigningCommitment) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseSigningCommitment) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.SigningCommitmentQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.SigningCommitmentQuery", q)
}

// The SigningKeyshareFunc type is an adapter to allow the use of ordinary function as a Querier.
type SigningKeyshareFunc func(context.Context, *ent.SigningKeyshareQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f SigningKeyshareFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.SigningKeyshareQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.SigningKeyshareQuery", q)
}

// The TraverseSigningKeyshare type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSigningKeyshare func(context.Context, *ent.SigningKeyshareQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSigningKeyshare) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseSigningKeyshare) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.SigningKeyshareQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.SigningKeyshareQuery", q)
}

// The SigningNonceFunc type is an adapter to allow the use of ordinary function as a Querier.
type SigningNonceFunc func(context.Context, *ent.SigningNonceQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f SigningNonceFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.SigningNonceQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.SigningNonceQuery", q)
}

// The TraverseSigningNonce type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSigningNonce func(context.Context, *ent.SigningNonceQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSigningNonce) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseSigningNonce) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.SigningNonceQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.SigningNonceQuery", q)
}

// The SparkInvoiceFunc type is an adapter to allow the use of ordinary function as a Querier.
type SparkInvoiceFunc func(context.Context, *ent.SparkInvoiceQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f SparkInvoiceFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.SparkInvoiceQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.SparkInvoiceQuery", q)
}

// The TraverseSparkInvoice type is an adapter to allow the use of ordinary function as Traverser.
type TraverseSparkInvoice func(context.Context, *ent.SparkInvoiceQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseSparkInvoice) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseSparkInvoice) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.SparkInvoiceQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.SparkInvoiceQuery", q)
}

// The TokenCreateFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenCreateFunc func(context.Context, *ent.TokenCreateQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenCreateFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenCreateQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenCreateQuery", q)
}

// The TraverseTokenCreate type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenCreate func(context.Context, *ent.TokenCreateQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenCreate) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenCreate) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenCreateQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenCreateQuery", q)
}

// The TokenFreezeFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenFreezeFunc func(context.Context, *ent.TokenFreezeQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenFreezeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenFreezeQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenFreezeQuery", q)
}

// The TraverseTokenFreeze type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenFreeze func(context.Context, *ent.TokenFreezeQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenFreeze) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenFreeze) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenFreezeQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenFreezeQuery", q)
}

// The TokenMintFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenMintFunc func(context.Context, *ent.TokenMintQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenMintFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenMintQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenMintQuery", q)
}

// The TraverseTokenMint type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenMint func(context.Context, *ent.TokenMintQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenMint) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenMint) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenMintQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenMintQuery", q)
}

// The TokenOutputFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenOutputFunc func(context.Context, *ent.TokenOutputQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenOutputFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenOutputQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenOutputQuery", q)
}

// The TraverseTokenOutput type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenOutput func(context.Context, *ent.TokenOutputQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenOutput) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenOutput) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenOutputQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenOutputQuery", q)
}

// The TokenPartialRevocationSecretShareFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenPartialRevocationSecretShareFunc func(context.Context, *ent.TokenPartialRevocationSecretShareQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenPartialRevocationSecretShareFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenPartialRevocationSecretShareQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenPartialRevocationSecretShareQuery", q)
}

// The TraverseTokenPartialRevocationSecretShare type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenPartialRevocationSecretShare func(context.Context, *ent.TokenPartialRevocationSecretShareQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenPartialRevocationSecretShare) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenPartialRevocationSecretShare) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenPartialRevocationSecretShareQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenPartialRevocationSecretShareQuery", q)
}

// The TokenTransactionFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenTransactionFunc func(context.Context, *ent.TokenTransactionQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenTransactionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenTransactionQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenTransactionQuery", q)
}

// The TraverseTokenTransaction type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenTransaction func(context.Context, *ent.TokenTransactionQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenTransaction) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenTransaction) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenTransactionQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenTransactionQuery", q)
}

// The TokenTransactionPeerSignatureFunc type is an adapter to allow the use of ordinary function as a Querier.
type TokenTransactionPeerSignatureFunc func(context.Context, *ent.TokenTransactionPeerSignatureQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TokenTransactionPeerSignatureFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TokenTransactionPeerSignatureQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TokenTransactionPeerSignatureQuery", q)
}

// The TraverseTokenTransactionPeerSignature type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTokenTransactionPeerSignature func(context.Context, *ent.TokenTransactionPeerSignatureQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTokenTransactionPeerSignature) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTokenTransactionPeerSignature) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TokenTransactionPeerSignatureQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TokenTransactionPeerSignatureQuery", q)
}

// The TransferFunc type is an adapter to allow the use of ordinary function as a Querier.
type TransferFunc func(context.Context, *ent.TransferQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TransferFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TransferQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TransferQuery", q)
}

// The TraverseTransfer type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTransfer func(context.Context, *ent.TransferQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTransfer) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTransfer) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TransferQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TransferQuery", q)
}

// The TransferLeafFunc type is an adapter to allow the use of ordinary function as a Querier.
type TransferLeafFunc func(context.Context, *ent.TransferLeafQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TransferLeafFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TransferLeafQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TransferLeafQuery", q)
}

// The TraverseTransferLeaf type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTransferLeaf func(context.Context, *ent.TransferLeafQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTransferLeaf) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTransferLeaf) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TransferLeafQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TransferLeafQuery", q)
}

// The TreeFunc type is an adapter to allow the use of ordinary function as a Querier.
type TreeFunc func(context.Context, *ent.TreeQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TreeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TreeQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TreeQuery", q)
}

// The TraverseTree type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTree func(context.Context, *ent.TreeQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTree) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTree) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TreeQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TreeQuery", q)
}

// The TreeNodeFunc type is an adapter to allow the use of ordinary function as a Querier.
type TreeNodeFunc func(context.Context, *ent.TreeNodeQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f TreeNodeFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.TreeNodeQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.TreeNodeQuery", q)
}

// The TraverseTreeNode type is an adapter to allow the use of ordinary function as Traverser.
type TraverseTreeNode func(context.Context, *ent.TreeNodeQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseTreeNode) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseTreeNode) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.TreeNodeQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.TreeNodeQuery", q)
}

// The UserSignedTransactionFunc type is an adapter to allow the use of ordinary function as a Querier.
type UserSignedTransactionFunc func(context.Context, *ent.UserSignedTransactionQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f UserSignedTransactionFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.UserSignedTransactionQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.UserSignedTransactionQuery", q)
}

// The TraverseUserSignedTransaction type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUserSignedTransaction func(context.Context, *ent.UserSignedTransactionQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUserSignedTransaction) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseUserSignedTransaction) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.UserSignedTransactionQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.UserSignedTransactionQuery", q)
}

// The UtxoFunc type is an adapter to allow the use of ordinary function as a Querier.
type UtxoFunc func(context.Context, *ent.UtxoQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f UtxoFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.UtxoQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.UtxoQuery", q)
}

// The TraverseUtxo type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUtxo func(context.Context, *ent.UtxoQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUtxo) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseUtxo) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.UtxoQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.UtxoQuery", q)
}

// The UtxoSwapFunc type is an adapter to allow the use of ordinary function as a Querier.
type UtxoSwapFunc func(context.Context, *ent.UtxoSwapQuery) (ent.Value, error)

// Query calls f(ctx, q).
func (f UtxoSwapFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
	if q, ok := q.(*ent.UtxoSwapQuery); ok {
		return f(ctx, q)
	}
	return nil, fmt.Errorf("unexpected query type %T. expect *ent.UtxoSwapQuery", q)
}

// The TraverseUtxoSwap type is an adapter to allow the use of ordinary function as Traverser.
type TraverseUtxoSwap func(context.Context, *ent.UtxoSwapQuery) error

// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseUtxoSwap) Intercept(next ent.Querier) ent.Querier {
	return next
}

// Traverse calls f(ctx, q).
func (f TraverseUtxoSwap) Traverse(ctx context.Context, q ent.Query) error {
	if q, ok := q.(*ent.UtxoSwapQuery); ok {
		return f(ctx, q)
	}
	return fmt.Errorf("unexpected query type %T. expect *ent.UtxoSwapQuery", q)
}

// NewQuery returns the generic Query interface for the given typed query.
func NewQuery(q ent.Query) (Query, error) {
	switch q := q.(type) {
	case *ent.BlockHeightQuery:
		return &query[*ent.BlockHeightQuery, predicate.BlockHeight, blockheight.OrderOption]{typ: ent.TypeBlockHeight, tq: q}, nil
	case *ent.CooperativeExitQuery:
		return &query[*ent.CooperativeExitQuery, predicate.CooperativeExit, cooperativeexit.OrderOption]{typ: ent.TypeCooperativeExit, tq: q}, nil
	case *ent.DepositAddressQuery:
		return &query[*ent.DepositAddressQuery, predicate.DepositAddress, depositaddress.OrderOption]{typ: ent.TypeDepositAddress, tq: q}, nil
	case *ent.EntityDkgKeyQuery:
		return &query[*ent.EntityDkgKeyQuery, predicate.EntityDkgKey, entitydkgkey.OrderOption]{typ: ent.TypeEntityDkgKey, tq: q}, nil
	case *ent.GossipQuery:
		return &query[*ent.GossipQuery, predicate.Gossip, gossip.OrderOption]{typ: ent.TypeGossip, tq: q}, nil
	case *ent.L1TokenCreateQuery:
		return &query[*ent.L1TokenCreateQuery, predicate.L1TokenCreate, l1tokencreate.OrderOption]{typ: ent.TypeL1TokenCreate, tq: q}, nil
	case *ent.PaymentIntentQuery:
		return &query[*ent.PaymentIntentQuery, predicate.PaymentIntent, paymentintent.OrderOption]{typ: ent.TypePaymentIntent, tq: q}, nil
	case *ent.PendingSendTransferQuery:
		return &query[*ent.PendingSendTransferQuery, predicate.PendingSendTransfer, pendingsendtransfer.OrderOption]{typ: ent.TypePendingSendTransfer, tq: q}, nil
	case *ent.PreimageRequestQuery:
		return &query[*ent.PreimageRequestQuery, predicate.PreimageRequest, preimagerequest.OrderOption]{typ: ent.TypePreimageRequest, tq: q}, nil
	case *ent.PreimageShareQuery:
		return &query[*ent.PreimageShareQuery, predicate.PreimageShare, preimageshare.OrderOption]{typ: ent.TypePreimageShare, tq: q}, nil
	case *ent.SigningCommitmentQuery:
		return &query[*ent.SigningCommitmentQuery, predicate.SigningCommitment, signingcommitment.OrderOption]{typ: ent.TypeSigningCommitment, tq: q}, nil
	case *ent.SigningKeyshareQuery:
		return &query[*ent.SigningKeyshareQuery, predicate.SigningKeyshare, signingkeyshare.OrderOption]{typ: ent.TypeSigningKeyshare, tq: q}, nil
	case *ent.SigningNonceQuery:
		return &query[*ent.SigningNonceQuery, predicate.SigningNonce, signingnonce.OrderOption]{typ: ent.TypeSigningNonce, tq: q}, nil
	case *ent.SparkInvoiceQuery:
		return &query[*ent.SparkInvoiceQuery, predicate.SparkInvoice, sparkinvoice.OrderOption]{typ: ent.TypeSparkInvoice, tq: q}, nil
	case *ent.TokenCreateQuery:
		return &query[*ent.TokenCreateQuery, predicate.TokenCreate, tokencreate.OrderOption]{typ: ent.TypeTokenCreate, tq: q}, nil
	case *ent.TokenFreezeQuery:
		return &query[*ent.TokenFreezeQuery, predicate.TokenFreeze, tokenfreeze.OrderOption]{typ: ent.TypeTokenFreeze, tq: q}, nil
	case *ent.TokenMintQuery:
		return &query[*ent.TokenMintQuery, predicate.TokenMint, tokenmint.OrderOption]{typ: ent.TypeTokenMint, tq: q}, nil
	case *ent.TokenOutputQuery:
		return &query[*ent.TokenOutputQuery, predicate.TokenOutput, tokenoutput.OrderOption]{typ: ent.TypeTokenOutput, tq: q}, nil
	case *ent.TokenPartialRevocationSecretShareQuery:
		return &query[*ent.TokenPartialRevocationSecretShareQuery, predicate.TokenPartialRevocationSecretShare, tokenpartialrevocationsecretshare.OrderOption]{typ: ent.TypeTokenPartialRevocationSecretShare, tq: q}, nil
	case *ent.TokenTransactionQuery:
		return &query[*ent.TokenTransactionQuery, predicate.TokenTransaction, tokentransaction.OrderOption]{typ: ent.TypeTokenTransaction, tq: q}, nil
	case *ent.TokenTransactionPeerSignatureQuery:
		return &query[*ent.TokenTransactionPeerSignatureQuery, predicate.TokenTransactionPeerSignature, tokentransactionpeersignature.OrderOption]{typ: ent.TypeTokenTransactionPeerSignature, tq: q}, nil
	case *ent.TransferQuery:
		return &query[*ent.TransferQuery, predicate.Transfer, transfer.OrderOption]{typ: ent.TypeTransfer, tq: q}, nil
	case *ent.TransferLeafQuery:
		return &query[*ent.TransferLeafQuery, predicate.TransferLeaf, transferleaf.OrderOption]{typ: ent.TypeTransferLeaf, tq: q}, nil
	case *ent.TreeQuery:
		return &query[*ent.TreeQuery, predicate.Tree, tree.OrderOption]{typ: ent.TypeTree, tq: q}, nil
	case *ent.TreeNodeQuery:
		return &query[*ent.TreeNodeQuery, predicate.TreeNode, treenode.OrderOption]{typ: ent.TypeTreeNode, tq: q}, nil
	case *ent.UserSignedTransactionQuery:
		return &query[*ent.UserSignedTransactionQuery, predicate.UserSignedTransaction, usersignedtransaction.OrderOption]{typ: ent.TypeUserSignedTransaction, tq: q}, nil
	case *ent.UtxoQuery:
		return &query[*ent.UtxoQuery, predicate.Utxo, utxo.OrderOption]{typ: ent.TypeUtxo, tq: q}, nil
	case *ent.UtxoSwapQuery:
		return &query[*ent.UtxoSwapQuery, predicate.UtxoSwap, utxoswap.OrderOption]{typ: ent.TypeUtxoSwap, tq: q}, nil
	default:
		return nil, fmt.Errorf("unknown query type %T", q)
	}
}

type query[T any, P ~func(*sql.Selector), R ~func(*sql.Selector)] struct {
	typ string
	tq  interface {
		Limit(int) T
		Offset(int) T
		Unique(bool) T
		Order(...R) T
		Where(...P) T
	}
}

func (q query[T, P, R]) Type() string {
	return q.typ
}

func (q query[T, P, R]) Limit(limit int) {
	q.tq.Limit(limit)
}

func (q query[T, P, R]) Offset(offset int) {
	q.tq.Offset(offset)
}

func (q query[T, P, R]) Unique(unique bool) {
	q.tq.Unique(unique)
}

func (q query[T, P, R]) Order(orders ...func(*sql.Selector)) {
	rs := make([]R, len(orders))
	for i := range orders {
		rs[i] = orders[i]
	}
	q.tq.Order(rs...)
}

func (q query[T, P, R]) WhereP(ps ...func(*sql.Selector)) {
	p := make([]P, len(ps))
	for i := range ps {
		p[i] = ps[i]
	}
	q.tq.Where(p...)
}
