// Code generated by go-enum DO NOT EDIT. // Version: // Revision: // Build Date: // Built By: package plugin import ( "database/sql/driver" "encoding/json" "errors" "fmt" "io" "strings" ) const ( ActivationEnabled Activation = "enabled" ActivationDisabled Activation = "disabled" ActivationAuto Activation = "auto" ActivationAlways Activation = "always" ) var ErrInvalidActivation = fmt.Errorf("not a valid Activation, try [%s]", strings.Join(_ActivationNames, ", ")) var _ActivationNames = []string{ string(ActivationEnabled), string(ActivationDisabled), string(ActivationAuto), string(ActivationAlways), } // ActivationNames returns a list of possible string values of Activation. func ActivationNames() []string { tmp := make([]string, len(_ActivationNames)) copy(tmp, _ActivationNames) return tmp } // ActivationValues returns a list of the values for Activation func ActivationValues() []Activation { return []Activation{ ActivationEnabled, ActivationDisabled, ActivationAuto, ActivationAlways, } } // String implements the Stringer interface. func (x Activation) 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 Activation) IsValid() bool { _, err := ParseActivation(string(x)) return err == nil } var _ActivationValue = map[string]Activation{ "enabled": ActivationEnabled, "disabled": ActivationDisabled, "auto": ActivationAuto, "always": ActivationAlways, } // ParseActivation attempts to convert a string to a Activation. func ParseActivation(name string) (Activation, error) { if x, ok := _ActivationValue[name]; ok { return x, nil } return Activation(""), fmt.Errorf("%s is %w", name, ErrInvalidActivation) } // MarshalText implements the text marshaller method. func (x Activation) MarshalText() ([]byte, error) { return []byte(string(x)), nil } // UnmarshalText implements the text unmarshaller method. func (x *Activation) UnmarshalText(text []byte) error { tmp, err := ParseActivation(string(text)) if err != nil { return err } *x = tmp return nil } var errActivationNilPtr = errors.New("value pointer is nil") // one per type for package clashes // Scan implements the Scanner interface. func (x *Activation) Scan(value interface{}) (err error) { if value == nil { *x = Activation("") 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 = ParseActivation(v) case []byte: *x, err = ParseActivation(string(v)) case Activation: *x = v case *Activation: if v == nil { return errActivationNilPtr } *x = *v case *string: if v == nil { return errActivationNilPtr } *x, err = ParseActivation(*v) default: return errors.New("invalid type for Activation") } return } // Value implements the driver Valuer interface. func (x Activation) Value() (driver.Value, error) { return x.String(), nil } type NullActivation struct { Activation Activation Valid bool Set bool } func NewNullActivation(val interface{}) (x NullActivation) { 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 *NullActivation) Scan(value interface{}) (err error) { if value == nil { x.Activation, x.Valid = Activation(""), false return } err = x.Activation.Scan(value) x.Valid = (err == nil) return } // Value implements the driver Valuer interface. func (x NullActivation) Value() (driver.Value, error) { if !x.Valid { return nil, nil } return x.Activation.String(), nil } // MarshalJSON correctly serializes a NullActivation to JSON. func (n NullActivation) MarshalJSON() ([]byte, error) { const nullStr = "null" if n.Valid { return json.Marshal(n.Activation) } return []byte(nullStr), nil } // UnmarshalJSON correctly deserializes a NullActivation from JSON. func (n *NullActivation) 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 } // MarshalGQL correctly serializes a NullActivation to GraphQL. func (n NullActivation) MarshalGQL(w io.Writer) { bytes, err := json.Marshal(n) if err == nil { _, _ = w.Write(bytes) } } // UnmarshalGQL correctly deserializes a NullActivation from GraphQL. func (n *NullActivation) UnmarshalGQL(v any) error { if v == nil { return nil } str, ok := v.(string) if !ok { return errors.New("value is not a string") } if str == "null" { return nil } return n.UnmarshalJSON([]byte("\"" + str + "\"")) }