// Code generated by ent, DO NOT EDIT.

package link

import (
	"fmt"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
)

const (
	// Label holds the string label denoting the link type in the database.
	Label = "link"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldName holds the string denoting the name field in the database.
	FieldName = "name"
	// FieldURL holds the string denoting the url field in the database.
	FieldURL = "url"
	// FieldLogo holds the string denoting the logo field in the database.
	FieldLogo = "logo"
	// FieldDescription holds the string denoting the description field in the database.
	FieldDescription = "description"
	// FieldStatus holds the string denoting the status field in the database.
	FieldStatus = "status"
	// FieldSiteshot holds the string denoting the siteshot field in the database.
	FieldSiteshot = "siteshot"
	// FieldSortOrder holds the string denoting the sort_order field in the database.
	FieldSortOrder = "sort_order"
	// FieldSkipHealthCheck holds the string denoting the skip_health_check field in the database.
	FieldSkipHealthCheck = "skip_health_check"
	// EdgeCategory holds the string denoting the category edge name in mutations.
	EdgeCategory = "category"
	// EdgeTags holds the string denoting the tags edge name in mutations.
	EdgeTags = "tags"
	// Table holds the table name of the link in the database.
	Table = "links"
	// CategoryTable is the table that holds the category relation/edge.
	CategoryTable = "links"
	// CategoryInverseTable is the table name for the LinkCategory entity.
	// It exists in this package in order to avoid circular dependency with the "linkcategory" package.
	CategoryInverseTable = "link_categories"
	// CategoryColumn is the table column denoting the category relation/edge.
	CategoryColumn = "link_category_links"
	// TagsTable is the table that holds the tags relation/edge. The primary key declared below.
	TagsTable = "link_tag_pivot"
	// TagsInverseTable is the table name for the LinkTag entity.
	// It exists in this package in order to avoid circular dependency with the "linktag" package.
	TagsInverseTable = "link_tags"
)

// Columns holds all SQL columns for link fields.
var Columns = []string{
	FieldID,
	FieldName,
	FieldURL,
	FieldLogo,
	FieldDescription,
	FieldStatus,
	FieldSiteshot,
	FieldSortOrder,
	FieldSkipHealthCheck,
}

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

var (
	// TagsPrimaryKey and TagsColumn2 are the table columns denoting the
	// primary key for the tags relation (M2M).
	TagsPrimaryKey = []string{"link_id", "link_tag_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
		}
	}
	for i := range ForeignKeys {
		if column == ForeignKeys[i] {
			return true
		}
	}
	return false
}

var (
	// NameValidator is a validator for the "name" field. It is called by the builders before save.
	NameValidator func(string) error
	// URLValidator is a validator for the "url" field. It is called by the builders before save.
	URLValidator func(string) error
	// DefaultSortOrder holds the default value on creation for the "sort_order" field.
	DefaultSortOrder int
	// DefaultSkipHealthCheck holds the default value on creation for the "skip_health_check" field.
	DefaultSkipHealthCheck bool
)

// Status defines the type for the "status" enum field.
type Status string

// StatusPENDING is the default value of the Status enum.
const DefaultStatus = StatusPENDING

// Status values.
const (
	StatusPENDING  Status = "PENDING"
	StatusAPPROVED Status = "APPROVED"
	StatusREJECTED Status = "REJECTED"
	StatusINVALID  Status = "INVALID"
)

func (s Status) String() string {
	return string(s)
}

// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
func StatusValidator(s Status) error {
	switch s {
	case StatusPENDING, StatusAPPROVED, StatusREJECTED, StatusINVALID:
		return nil
	default:
		return fmt.Errorf("link: invalid enum value for status field: %q", s)
	}
}

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

// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldName, opts...).ToFunc()
}

// ByURL orders the results by the url field.
func ByURL(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldURL, opts...).ToFunc()
}

// ByLogo orders the results by the logo field.
func ByLogo(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldLogo, opts...).ToFunc()
}

// ByDescription orders the results by the description field.
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldDescription, opts...).ToFunc()
}

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

// BySiteshot orders the results by the siteshot field.
func BySiteshot(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldSiteshot, opts...).ToFunc()
}

// BySortOrder orders the results by the sort_order field.
func BySortOrder(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldSortOrder, opts...).ToFunc()
}

// BySkipHealthCheck orders the results by the skip_health_check field.
func BySkipHealthCheck(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldSkipHealthCheck, opts...).ToFunc()
}

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

// ByTagsCount orders the results by tags count.
func ByTagsCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newTagsStep(), opts...)
	}
}

// ByTags orders the results by tags terms.
func ByTags(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newTagsStep(), append([]sql.OrderTerm{term}, terms...)...)
	}
}
func newCategoryStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(CategoryInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, true, CategoryTable, CategoryColumn),
	)
}
func newTagsStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(TagsInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2M, false, TagsTable, TagsPrimaryKey...),
	)
}
