// Code generated by go-enum DO NOT EDIT.
// Version:
// Revision:
// Build Date:
// Built By:

package search

import (
	"database/sql/driver"
	"encoding/json"
	"errors"
	"fmt"
	"strings"
)

const (
	QueueJobsOrderByCreatedAt QueueJobsOrderBy = "created_at"
	QueueJobsOrderByRanAt     QueueJobsOrderBy = "ran_at"
	QueueJobsOrderByPriority  QueueJobsOrderBy = "priority"
)

var ErrInvalidQueueJobsOrderBy = fmt.Errorf("not a valid QueueJobsOrderBy, try [%s]", strings.Join(_QueueJobsOrderByNames, ", "))

var _QueueJobsOrderByNames = []string{
	string(QueueJobsOrderByCreatedAt),
	string(QueueJobsOrderByRanAt),
	string(QueueJobsOrderByPriority),
}

// QueueJobsOrderByNames returns a list of possible string values of QueueJobsOrderBy.
func QueueJobsOrderByNames() []string {
	tmp := make([]string, len(_QueueJobsOrderByNames))
	copy(tmp, _QueueJobsOrderByNames)
	return tmp
}

// QueueJobsOrderByValues returns a list of the values for QueueJobsOrderBy
func QueueJobsOrderByValues() []QueueJobsOrderBy {
	return []QueueJobsOrderBy{
		QueueJobsOrderByCreatedAt,
		QueueJobsOrderByRanAt,
		QueueJobsOrderByPriority,
	}
}

// String implements the Stringer interface.
func (x QueueJobsOrderBy) String() string {
	return string(x)
}

// IsValid provides a quick way to determine if the typed value is
// part of the allowed enumerated values
func (x QueueJobsOrderBy) IsValid() bool {
	_, err := ParseQueueJobsOrderBy(string(x))
	return err == nil
}

var _QueueJobsOrderByValue = map[string]QueueJobsOrderBy{
	"created_at": QueueJobsOrderByCreatedAt,
	"ran_at":     QueueJobsOrderByRanAt,
	"priority":   QueueJobsOrderByPriority,
}

// ParseQueueJobsOrderBy attempts to convert a string to a QueueJobsOrderBy.
func ParseQueueJobsOrderBy(name string) (QueueJobsOrderBy, error) {
	if x, ok := _QueueJobsOrderByValue[name]; ok {
		return x, nil
	}
	// Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to.
	if x, ok := _QueueJobsOrderByValue[strings.ToLower(name)]; ok {
		return x, nil
	}
	return QueueJobsOrderBy(""), fmt.Errorf("%s is %w", name, ErrInvalidQueueJobsOrderBy)
}

// MarshalText implements the text marshaller method.
func (x QueueJobsOrderBy) MarshalText() ([]byte, error) {
	return []byte(string(x)), nil
}

// UnmarshalText implements the text unmarshaller method.
func (x *QueueJobsOrderBy) UnmarshalText(text []byte) error {
	tmp, err := ParseQueueJobsOrderBy(string(text))
	if err != nil {
		return err
	}
	*x = tmp
	return nil
}

var errQueueJobsOrderByNilPtr = errors.New("value pointer is nil") // one per type for package clashes

// Scan implements the Scanner interface.
func (x *QueueJobsOrderBy) Scan(value interface{}) (err error) {
	if value == nil {
		*x = QueueJobsOrderBy("")
		return
	}

	// A wider range of scannable types.
	// driver.Value values at the top of the list for expediency
	switch v := value.(type) {
	case string:
		*x, err = ParseQueueJobsOrderBy(v)
	case []byte:
		*x, err = ParseQueueJobsOrderBy(string(v))
	case QueueJobsOrderBy:
		*x = v
	case *QueueJobsOrderBy:
		if v == nil {
			return errQueueJobsOrderByNilPtr
		}
		*x = *v
	case *string:
		if v == nil {
			return errQueueJobsOrderByNilPtr
		}
		*x, err = ParseQueueJobsOrderBy(*v)
	default:
		return errors.New("invalid type for QueueJobsOrderBy")
	}

	return
}

// Value implements the driver Valuer interface.
func (x QueueJobsOrderBy) Value() (driver.Value, error) {
	return x.String(), nil
}

type NullQueueJobsOrderBy struct {
	QueueJobsOrderBy QueueJobsOrderBy
	Valid            bool
	Set              bool
}

func NewNullQueueJobsOrderBy(val interface{}) (x NullQueueJobsOrderBy) {
	err := x.Scan(val) // yes, we ignore this error, it will just be an invalid value.
	_ = err            // make any errcheck linters happy
	return
}

// Scan implements the Scanner interface.
func (x *NullQueueJobsOrderBy) Scan(value interface{}) (err error) {
	if value == nil {
		x.QueueJobsOrderBy, x.Valid = QueueJobsOrderBy(""), false
		return
	}

	err = x.QueueJobsOrderBy.Scan(value)
	x.Valid = (err == nil)
	return
}

// Value implements the driver Valuer interface.
func (x NullQueueJobsOrderBy) Value() (driver.Value, error) {
	if !x.Valid {
		return nil, nil
	}
	return x.QueueJobsOrderBy.String(), nil
}

// MarshalJSON correctly serializes a NullQueueJobsOrderBy to JSON.
func (n NullQueueJobsOrderBy) MarshalJSON() ([]byte, error) {
	const nullStr = "null"
	if n.Valid {
		return json.Marshal(n.QueueJobsOrderBy)
	}
	return []byte(nullStr), nil
}

// UnmarshalJSON correctly deserializes a NullQueueJobsOrderBy from JSON.
func (n *NullQueueJobsOrderBy) UnmarshalJSON(b []byte) error {
	n.Set = true
	var x interface{}
	err := json.Unmarshal(b, &x)
	if err != nil {
		return err
	}
	err = n.Scan(x)
	return err
}
