// Code generated by ent, DO NOT EDIT.

package missdetail

import (
	"fmt"
	"io"
	"strconv"

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

const (
	// Label holds the string label denoting the missdetail type in the database.
	Label = "miss_detail"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldReason holds the string denoting the reason field in the database.
	FieldReason = "reason"
	// FieldCount holds the string denoting the count field in the database.
	FieldCount = "count"
	// EdgeActionCacheStatistics holds the string denoting the action_cache_statistics edge name in mutations.
	EdgeActionCacheStatistics = "action_cache_statistics"
	// Table holds the table name of the missdetail in the database.
	Table = "miss_details"
	// ActionCacheStatisticsTable is the table that holds the action_cache_statistics relation/edge.
	ActionCacheStatisticsTable = "miss_details"
	// ActionCacheStatisticsInverseTable is the table name for the ActionCacheStatistics entity.
	// It exists in this package in order to avoid circular dependency with the "actioncachestatistics" package.
	ActionCacheStatisticsInverseTable = "action_cache_statistics"
	// ActionCacheStatisticsColumn is the table column denoting the action_cache_statistics relation/edge.
	ActionCacheStatisticsColumn = "action_cache_statistics_miss_details"
)

// Columns holds all SQL columns for missdetail fields.
var Columns = []string{
	FieldID,
	FieldReason,
	FieldCount,
}

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

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

// Reason defines the type for the "reason" enum field.
type Reason string

// ReasonUNKNOWN is the default value of the Reason enum.
const DefaultReason = ReasonUNKNOWN

// Reason values.
const (
	ReasonDIFFERENT_ACTION_KEY    Reason = "DIFFERENT_ACTION_KEY"
	ReasonDIFFERENT_DEPS          Reason = "DIFFERENT_DEPS"
	ReasonDIFFERENT_ENVIRONMENT   Reason = "DIFFERENT_ENVIRONMENT"
	ReasonDIFFERENT_FILES         Reason = "DIFFERENT_FILES"
	ReasonCORRUPTED_CACHE_ENTRY   Reason = "CORRUPTED_CACHE_ENTRY"
	ReasonNOT_CACHED              Reason = "NOT_CACHED"
	ReasonUNCONDITIONAL_EXECUTION Reason = "UNCONDITIONAL_EXECUTION"
	ReasonUNKNOWN                 Reason = "UNKNOWN"
)

func (r Reason) String() string {
	return string(r)
}

// ReasonValidator is a validator for the "reason" field enum values. It is called by the builders before save.
func ReasonValidator(r Reason) error {
	switch r {
	case ReasonDIFFERENT_ACTION_KEY, ReasonDIFFERENT_DEPS, ReasonDIFFERENT_ENVIRONMENT, ReasonDIFFERENT_FILES, ReasonCORRUPTED_CACHE_ENTRY, ReasonNOT_CACHED, ReasonUNCONDITIONAL_EXECUTION, ReasonUNKNOWN:
		return nil
	default:
		return fmt.Errorf("missdetail: invalid enum value for reason field: %q", r)
	}
}

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

// ByReason orders the results by the reason field.
func ByReason(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldReason, opts...).ToFunc()
}

// ByCount orders the results by the count field.
func ByCount(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldCount, opts...).ToFunc()
}

// ByActionCacheStatisticsField orders the results by action_cache_statistics field.
func ByActionCacheStatisticsField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newActionCacheStatisticsStep(), sql.OrderByField(field, opts...))
	}
}
func newActionCacheStatisticsStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(ActionCacheStatisticsInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, true, ActionCacheStatisticsTable, ActionCacheStatisticsColumn),
	)
}

// MarshalGQL implements graphql.Marshaler interface.
func (e Reason) MarshalGQL(w io.Writer) {
	io.WriteString(w, strconv.Quote(e.String()))
}

// UnmarshalGQL implements graphql.Unmarshaler interface.
func (e *Reason) UnmarshalGQL(val interface{}) error {
	str, ok := val.(string)
	if !ok {
		return fmt.Errorf("enum %T must be a string", val)
	}
	*e = Reason(str)
	if err := ReasonValidator(*e); err != nil {
		return fmt.Errorf("%s is not a valid Reason", str)
	}
	return nil
}
