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

package model

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

const (
	VideoSourceCAM       VideoSource = "CAM"
	VideoSourceTELESYNC  VideoSource = "TELESYNC"
	VideoSourceTELECINE  VideoSource = "TELECINE"
	VideoSourceWORKPRINT VideoSource = "WORKPRINT"
	VideoSourceDVD       VideoSource = "DVD"
	VideoSourceTV        VideoSource = "TV"
	VideoSourceWEBDL     VideoSource = "WEBDL"
	VideoSourceWEBRip    VideoSource = "WEBRip"
	VideoSourceBluRay    VideoSource = "BluRay"
)

var ErrInvalidVideoSource = fmt.Errorf("not a valid VideoSource, try [%s]", strings.Join(_VideoSourceNames, ", "))

var _VideoSourceNames = []string{
	string(VideoSourceCAM),
	string(VideoSourceTELESYNC),
	string(VideoSourceTELECINE),
	string(VideoSourceWORKPRINT),
	string(VideoSourceDVD),
	string(VideoSourceTV),
	string(VideoSourceWEBDL),
	string(VideoSourceWEBRip),
	string(VideoSourceBluRay),
}

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

// VideoSourceValues returns a list of the values for VideoSource
func VideoSourceValues() []VideoSource {
	return []VideoSource{
		VideoSourceCAM,
		VideoSourceTELESYNC,
		VideoSourceTELECINE,
		VideoSourceWORKPRINT,
		VideoSourceDVD,
		VideoSourceTV,
		VideoSourceWEBDL,
		VideoSourceWEBRip,
		VideoSourceBluRay,
	}
}

// String implements the Stringer interface.
func (x VideoSource) 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 VideoSource) IsValid() bool {
	_, err := ParseVideoSource(string(x))
	return err == nil
}

var _VideoSourceValue = map[string]VideoSource{
	"CAM":       VideoSourceCAM,
	"cam":       VideoSourceCAM,
	"TELESYNC":  VideoSourceTELESYNC,
	"telesync":  VideoSourceTELESYNC,
	"TELECINE":  VideoSourceTELECINE,
	"telecine":  VideoSourceTELECINE,
	"WORKPRINT": VideoSourceWORKPRINT,
	"workprint": VideoSourceWORKPRINT,
	"DVD":       VideoSourceDVD,
	"dvd":       VideoSourceDVD,
	"TV":        VideoSourceTV,
	"tv":        VideoSourceTV,
	"WEBDL":     VideoSourceWEBDL,
	"webdl":     VideoSourceWEBDL,
	"WEBRip":    VideoSourceWEBRip,
	"webrip":    VideoSourceWEBRip,
	"BluRay":    VideoSourceBluRay,
	"bluray":    VideoSourceBluRay,
}

// ParseVideoSource attempts to convert a string to a VideoSource.
func ParseVideoSource(name string) (VideoSource, error) {
	if x, ok := _VideoSourceValue[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 := _VideoSourceValue[strings.ToLower(name)]; ok {
		return x, nil
	}
	return VideoSource(""), fmt.Errorf("%s is %w", name, ErrInvalidVideoSource)
}

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

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

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

// Scan implements the Scanner interface.
func (x *VideoSource) Scan(value interface{}) (err error) {
	if value == nil {
		*x = VideoSource("")
		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 = ParseVideoSource(v)
	case []byte:
		*x, err = ParseVideoSource(string(v))
	case VideoSource:
		*x = v
	case *VideoSource:
		if v == nil {
			return errVideoSourceNilPtr
		}
		*x = *v
	case *string:
		if v == nil {
			return errVideoSourceNilPtr
		}
		*x, err = ParseVideoSource(*v)
	default:
		return errors.New("invalid type for VideoSource")
	}

	return
}

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

type NullVideoSource struct {
	VideoSource VideoSource
	Valid       bool
	Set         bool
}

func NewNullVideoSource(val interface{}) (x NullVideoSource) {
	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 *NullVideoSource) Scan(value interface{}) (err error) {
	if value == nil {
		x.VideoSource, x.Valid = VideoSource(""), false
		return
	}

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

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

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

// UnmarshalJSON correctly deserializes a NullVideoSource from JSON.
func (n *NullVideoSource) 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 NullVideoSource to GraphQL.
func (n NullVideoSource) MarshalGQL(w io.Writer) {
	bytes, err := json.Marshal(n)
	if err == nil {
		_, _ = w.Write(bytes)
	}
}

// UnmarshalGQL correctly deserializes a NullVideoSource from GraphQL.
func (n *NullVideoSource) 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 + "\""))
}
