// Code generated by ent, DO NOT EDIT.

package testcollection

import (
	"fmt"
	"io"
	"strconv"

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

const (
	// Label holds the string label denoting the testcollection type in the database.
	Label = "test_collection"
	// 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"
	// FieldOverallStatus holds the string denoting the overall_status field in the database.
	FieldOverallStatus = "overall_status"
	// FieldStrategy holds the string denoting the strategy field in the database.
	FieldStrategy = "strategy"
	// FieldCachedLocally holds the string denoting the cached_locally field in the database.
	FieldCachedLocally = "cached_locally"
	// FieldCachedRemotely holds the string denoting the cached_remotely field in the database.
	FieldCachedRemotely = "cached_remotely"
	// FieldFirstSeen holds the string denoting the first_seen field in the database.
	FieldFirstSeen = "first_seen"
	// FieldDurationMs holds the string denoting the duration_ms field in the database.
	FieldDurationMs = "duration_ms"
	// EdgeBazelInvocation holds the string denoting the bazel_invocation edge name in mutations.
	EdgeBazelInvocation = "bazel_invocation"
	// EdgeTestSummary holds the string denoting the test_summary edge name in mutations.
	EdgeTestSummary = "test_summary"
	// EdgeTestResults holds the string denoting the test_results edge name in mutations.
	EdgeTestResults = "test_results"
	// Table holds the table name of the testcollection in the database.
	Table = "test_collections"
	// BazelInvocationTable is the table that holds the bazel_invocation relation/edge.
	BazelInvocationTable = "test_collections"
	// 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_test_collection"
	// TestSummaryTable is the table that holds the test_summary relation/edge.
	TestSummaryTable = "test_summaries"
	// TestSummaryInverseTable is the table name for the TestSummary entity.
	// It exists in this package in order to avoid circular dependency with the "testsummary" package.
	TestSummaryInverseTable = "test_summaries"
	// TestSummaryColumn is the table column denoting the test_summary relation/edge.
	TestSummaryColumn = "test_collection_test_summary"
	// TestResultsTable is the table that holds the test_results relation/edge.
	TestResultsTable = "test_result_be_ss"
	// TestResultsInverseTable is the table name for the TestResultBES entity.
	// It exists in this package in order to avoid circular dependency with the "testresultbes" package.
	TestResultsInverseTable = "test_result_be_ss"
	// TestResultsColumn is the table column denoting the test_results relation/edge.
	TestResultsColumn = "test_collection_test_results"
)

// Columns holds all SQL columns for testcollection fields.
var Columns = []string{
	FieldID,
	FieldLabel,
	FieldOverallStatus,
	FieldStrategy,
	FieldCachedLocally,
	FieldCachedRemotely,
	FieldFirstSeen,
	FieldDurationMs,
}

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

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

// OverallStatus defines the type for the "overall_status" enum field.
type OverallStatus string

// OverallStatusNO_STATUS is the default value of the OverallStatus enum.
const DefaultOverallStatus = OverallStatusNO_STATUS

// OverallStatus values.
const (
	OverallStatusNO_STATUS                  OverallStatus = "NO_STATUS"
	OverallStatusPASSED                     OverallStatus = "PASSED"
	OverallStatusFLAKY                      OverallStatus = "FLAKY"
	OverallStatusTIMEOUT                    OverallStatus = "TIMEOUT"
	OverallStatusFAILED                     OverallStatus = "FAILED"
	OverallStatusINCOMPLETE                 OverallStatus = "INCOMPLETE"
	OverallStatusREMOTE_FAILURE             OverallStatus = "REMOTE_FAILURE"
	OverallStatusFAILED_TO_BUILD            OverallStatus = "FAILED_TO_BUILD"
	OverallStatusTOOL_HALTED_BEFORE_TESTING OverallStatus = "TOOL_HALTED_BEFORE_TESTING"
)

func (os OverallStatus) String() string {
	return string(os)
}

// OverallStatusValidator is a validator for the "overall_status" field enum values. It is called by the builders before save.
func OverallStatusValidator(os OverallStatus) error {
	switch os {
	case OverallStatusNO_STATUS, OverallStatusPASSED, OverallStatusFLAKY, OverallStatusTIMEOUT, OverallStatusFAILED, OverallStatusINCOMPLETE, OverallStatusREMOTE_FAILURE, OverallStatusFAILED_TO_BUILD, OverallStatusTOOL_HALTED_BEFORE_TESTING:
		return nil
	default:
		return fmt.Errorf("testcollection: invalid enum value for overall_status field: %q", os)
	}
}

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

// ByOverallStatus orders the results by the overall_status field.
func ByOverallStatus(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldOverallStatus, opts...).ToFunc()
}

// ByStrategy orders the results by the strategy field.
func ByStrategy(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldStrategy, opts...).ToFunc()
}

// ByCachedLocally orders the results by the cached_locally field.
func ByCachedLocally(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldCachedLocally, opts...).ToFunc()
}

// ByCachedRemotely orders the results by the cached_remotely field.
func ByCachedRemotely(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldCachedRemotely, opts...).ToFunc()
}

// ByFirstSeen orders the results by the first_seen field.
func ByFirstSeen(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldFirstSeen, opts...).ToFunc()
}

// ByDurationMs orders the results by the duration_ms field.
func ByDurationMs(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldDurationMs, 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...))
	}
}

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

// ByTestResultsCount orders the results by test_results count.
func ByTestResultsCount(opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborsCount(s, newTestResultsStep(), opts...)
	}
}

// ByTestResults orders the results by test_results terms.
func ByTestResults(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newTestResultsStep(), append([]sql.OrderTerm{term}, terms...)...)
	}
}
func newBazelInvocationStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(BazelInvocationInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, true, BazelInvocationTable, BazelInvocationColumn),
	)
}
func newTestSummaryStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(TestSummaryInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.O2O, false, TestSummaryTable, TestSummaryColumn),
	)
}
func newTestResultsStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(TestResultsInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.O2M, false, TestResultsTable, TestResultsColumn),
	)
}

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

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