// Code generated by ent, DO NOT EDIT.

package referrer

import (
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"github.com/google/uuid"
)

const (
	// Label holds the string label denoting the referrer type in the database.
	Label = "referrer"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldDigest holds the string denoting the digest field in the database.
	FieldDigest = "digest"
	// FieldKind holds the string denoting the kind field in the database.
	FieldKind = "kind"
	// FieldDownloadable holds the string denoting the downloadable field in the database.
	FieldDownloadable = "downloadable"
	// FieldCreatedAt holds the string denoting the created_at field in the database.
	FieldCreatedAt = "created_at"
	// FieldMetadata holds the string denoting the metadata field in the database.
	FieldMetadata = "metadata"
	// FieldAnnotations holds the string denoting the annotations field in the database.
	FieldAnnotations = "annotations"
	// EdgeReferredBy holds the string denoting the referred_by edge name in mutations.
	EdgeReferredBy = "referred_by"
	// EdgeReferences holds the string denoting the references edge name in mutations.
	EdgeReferences = "references"
	// EdgeWorkflows holds the string denoting the workflows edge name in mutations.
	EdgeWorkflows = "workflows"
	// Table holds the table name of the referrer in the database.
	Table = "referrers"
	// ReferredByTable is the table that holds the referred_by relation/edge. The primary key declared below.
	ReferredByTable = "referrer_references"
	// ReferencesTable is the table that holds the references relation/edge. The primary key declared below.
	ReferencesTable = "referrer_references"
	// WorkflowsTable is the table that holds the workflows relation/edge. The primary key declared below.
	WorkflowsTable = "referrer_workflows"
	// WorkflowsInverseTable is the table name for the Workflow entity.
	// It exists in this package in order to avoid circular dependency with the "workflow" package.
	WorkflowsInverseTable = "workflows"
)

// Columns holds all SQL columns for referrer fields.
var Columns = []string{
	FieldID,
	FieldDigest,
	FieldKind,
	FieldDownloadable,
	FieldCreatedAt,
	FieldMetadata,
	FieldAnnotations,
}

var (
	// ReferredByPrimaryKey and ReferredByColumn2 are the table columns denoting the
	// primary key for the referred_by relation (M2M).
	ReferredByPrimaryKey = []string{"referrer_id", "referred_by_id"}
	// ReferencesPrimaryKey and ReferencesColumn2 are the table columns denoting the
	// primary key for the references relation (M2M).
	ReferencesPrimaryKey = []string{"referrer_id", "referred_by_id"}
	// WorkflowsPrimaryKey and WorkflowsColumn2 are the table columns denoting the
	// primary key for the workflows relation (M2M).
	WorkflowsPrimaryKey = []string{"referrer_id", "workflow_id"}
)

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

var (
	// DefaultCreatedAt holds the default value on creation for the "created_at" field.
	DefaultCreatedAt func() time.Time
	// DefaultID holds the default value on creation for the "id" field.
	DefaultID func() uuid.UUID
)

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

// ByDigest orders the results by the digest field.
func ByDigest(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldDigest, opts...).ToFunc()
}

// ByKind orders the results by the kind field.
func ByKind(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldKind, opts...).ToFunc()
}

// ByDownloadable orders the results by the downloadable field.
func ByDownloadable(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldDownloadable, opts...).ToFunc()
}

// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}

// ByReferredByCount orders the results by referred_by count.
func ByReferredByCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newReferredByStep(), opts...)
	}
}

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

// ByReferencesCount orders the results by references count.
func ByReferencesCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newReferencesStep(), opts...)
	}
}

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

// ByWorkflowsCount orders the results by workflows count.
func ByWorkflowsCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newWorkflowsStep(), opts...)
	}
}

// ByWorkflows orders the results by workflows terms.
func ByWorkflows(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newWorkflowsStep(), append([]sql.OrderTerm{term}, terms...)...)
	}
}
func newReferredByStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(Table, FieldID),
		sqlgraph.Edge(sqlgraph.M2M, true, ReferredByTable, ReferredByPrimaryKey...),
	)
}
func newReferencesStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(Table, FieldID),
		sqlgraph.Edge(sqlgraph.M2M, false, ReferencesTable, ReferencesPrimaryKey...),
	)
}
func newWorkflowsStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(WorkflowsInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2M, false, WorkflowsTable, WorkflowsPrimaryKey...),
	)
}
