// Code generated by ent, DO NOT EDIT.

package targetpair

import (
	"fmt"
	"io"
	"strconv"

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

const (
	// Label holds the string label denoting the targetpair type in the database.
	Label = "target_pair"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldLabel holds the string denoting the label field in the database.
	FieldLabel = "label"
	// FieldDurationInMs holds the string denoting the duration_in_ms field in the database.
	FieldDurationInMs = "duration_in_ms"
	// FieldSuccess holds the string denoting the success field in the database.
	FieldSuccess = "success"
	// FieldTargetKind holds the string denoting the target_kind field in the database.
	FieldTargetKind = "target_kind"
	// FieldTestSize holds the string denoting the test_size field in the database.
	FieldTestSize = "test_size"
	// FieldAbortReason holds the string denoting the abort_reason field in the database.
	FieldAbortReason = "abort_reason"
	// EdgeBazelInvocation holds the string denoting the bazel_invocation edge name in mutations.
	EdgeBazelInvocation = "bazel_invocation"
	// EdgeConfiguration holds the string denoting the configuration edge name in mutations.
	EdgeConfiguration = "configuration"
	// EdgeCompletion holds the string denoting the completion edge name in mutations.
	EdgeCompletion = "completion"
	// Table holds the table name of the targetpair in the database.
	Table = "target_pairs"
	// BazelInvocationTable is the table that holds the bazel_invocation relation/edge.
	BazelInvocationTable = "target_pairs"
	// BazelInvocationInverseTable is the table name for the BazelInvocation entity.
	// It exists in this package in order to avoid circular dependency with the "bazelinvocation" package.
	BazelInvocationInverseTable = "bazel_invocations"
	// BazelInvocationColumn is the table column denoting the bazel_invocation relation/edge.
	BazelInvocationColumn = "bazel_invocation_targets"
	// ConfigurationTable is the table that holds the configuration relation/edge.
	ConfigurationTable = "target_configureds"
	// ConfigurationInverseTable is the table name for the TargetConfigured entity.
	// It exists in this package in order to avoid circular dependency with the "targetconfigured" package.
	ConfigurationInverseTable = "target_configureds"
	// ConfigurationColumn is the table column denoting the configuration relation/edge.
	ConfigurationColumn = "target_pair_configuration"
	// CompletionTable is the table that holds the completion relation/edge.
	CompletionTable = "target_completes"
	// CompletionInverseTable is the table name for the TargetComplete entity.
	// It exists in this package in order to avoid circular dependency with the "targetcomplete" package.
	CompletionInverseTable = "target_completes"
	// CompletionColumn is the table column denoting the completion relation/edge.
	CompletionColumn = "target_pair_completion"
)

// Columns holds all SQL columns for targetpair fields.
var Columns = []string{
	FieldID,
	FieldLabel,
	FieldDurationInMs,
	FieldSuccess,
	FieldTargetKind,
	FieldTestSize,
	FieldAbortReason,
}

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

// 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 (
	// DefaultSuccess holds the default value on creation for the "success" field.
	DefaultSuccess bool
)

// TestSize defines the type for the "test_size" enum field.
type TestSize string

// TestSizeUNKNOWN is the default value of the TestSize enum.
const DefaultTestSize = TestSizeUNKNOWN

// TestSize values.
const (
	TestSizeUNKNOWN  TestSize = "UNKNOWN"
	TestSizeSMALL    TestSize = "SMALL"
	TestSizeMEDIUM   TestSize = "MEDIUM"
	TestSizeLARGE    TestSize = "LARGE"
	TestSizeENORMOUS TestSize = "ENORMOUS"
)

func (ts TestSize) String() string {
	return string(ts)
}

// TestSizeValidator is a validator for the "test_size" field enum values. It is called by the builders before save.
func TestSizeValidator(ts TestSize) error {
	switch ts {
	case TestSizeUNKNOWN, TestSizeSMALL, TestSizeMEDIUM, TestSizeLARGE, TestSizeENORMOUS:
		return nil
	default:
		return fmt.Errorf("targetpair: invalid enum value for test_size field: %q", ts)
	}
}

// AbortReason defines the type for the "abort_reason" enum field.
type AbortReason string

// AbortReason values.
const (
	AbortReasonUNKNOWN                    AbortReason = "UNKNOWN"
	AbortReasonUSER_INTERRUPTED           AbortReason = "USER_INTERRUPTED"
	AbortReasonNO_ANALYZE                 AbortReason = "NO_ANALYZE"
	AbortReasonNO_BUILD                   AbortReason = "NO_BUILD"
	AbortReasonTIME_OUT                   AbortReason = "TIME_OUT"
	AbortReasonREMOTE_ENVIRONMENT_FAILURE AbortReason = "REMOTE_ENVIRONMENT_FAILURE"
	AbortReasonINTERNAL                   AbortReason = "INTERNAL"
	AbortReasonLOADING_FAILURE            AbortReason = "LOADING_FAILURE"
	AbortReasonANALYSIS_FAILURE           AbortReason = "ANALYSIS_FAILURE"
	AbortReasonSKIPPED                    AbortReason = "SKIPPED"
	AbortReasonINCOMPLETE                 AbortReason = "INCOMPLETE"
	AbortReasonOUT_OF_MEMORY              AbortReason = "OUT_OF_MEMORY"
)

func (ar AbortReason) String() string {
	return string(ar)
}

// AbortReasonValidator is a validator for the "abort_reason" field enum values. It is called by the builders before save.
func AbortReasonValidator(ar AbortReason) error {
	switch ar {
	case AbortReasonUNKNOWN, AbortReasonUSER_INTERRUPTED, AbortReasonNO_ANALYZE, AbortReasonNO_BUILD, AbortReasonTIME_OUT, AbortReasonREMOTE_ENVIRONMENT_FAILURE, AbortReasonINTERNAL, AbortReasonLOADING_FAILURE, AbortReasonANALYSIS_FAILURE, AbortReasonSKIPPED, AbortReasonINCOMPLETE, AbortReasonOUT_OF_MEMORY:
		return nil
	default:
		return fmt.Errorf("targetpair: invalid enum value for abort_reason field: %q", ar)
	}
}

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

// ByLabel orders the results by the label field.
func ByLabel(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldLabel, opts...).ToFunc()
}

// ByDurationInMs orders the results by the duration_in_ms field.
func ByDurationInMs(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldDurationInMs, opts...).ToFunc()
}

// BySuccess orders the results by the success field.
func BySuccess(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldSuccess, opts...).ToFunc()
}

// ByTargetKind orders the results by the target_kind field.
func ByTargetKind(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldTargetKind, opts...).ToFunc()
}

// ByTestSize orders the results by the test_size field.
func ByTestSize(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldTestSize, opts...).ToFunc()
}

// ByAbortReason orders the results by the abort_reason field.
func ByAbortReason(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldAbortReason, opts...).ToFunc()
}

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

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

// ByCompletionField orders the results by completion field.
func ByCompletionField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newCompletionStep(), sql.OrderByField(field, opts...))
	}
}
func newBazelInvocationStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(BazelInvocationInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, true, BazelInvocationTable, BazelInvocationColumn),
	)
}
func newConfigurationStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(ConfigurationInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.O2O, false, ConfigurationTable, ConfigurationColumn),
	)
}
func newCompletionStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(CompletionInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.O2O, false, CompletionTable, CompletionColumn),
	)
}

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

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

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

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