// 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 (
	VideoResolutionV360p  VideoResolution = "V360p"
	VideoResolutionV480p  VideoResolution = "V480p"
	VideoResolutionV540p  VideoResolution = "V540p"
	VideoResolutionV576p  VideoResolution = "V576p"
	VideoResolutionV720p  VideoResolution = "V720p"
	VideoResolutionV1080p VideoResolution = "V1080p"
	VideoResolutionV1440p VideoResolution = "V1440p"
	VideoResolutionV2160p VideoResolution = "V2160p"
	VideoResolutionV4320p VideoResolution = "V4320p"
)

var ErrInvalidVideoResolution = fmt.Errorf("not a valid VideoResolution, try [%s]", strings.Join(_VideoResolutionNames, ", "))

var _VideoResolutionNames = []string{
	string(VideoResolutionV360p),
	string(VideoResolutionV480p),
	string(VideoResolutionV540p),
	string(VideoResolutionV576p),
	string(VideoResolutionV720p),
	string(VideoResolutionV1080p),
	string(VideoResolutionV1440p),
	string(VideoResolutionV2160p),
	string(VideoResolutionV4320p),
}

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

// VideoResolutionValues returns a list of the values for VideoResolution
func VideoResolutionValues() []VideoResolution {
	return []VideoResolution{
		VideoResolutionV360p,
		VideoResolutionV480p,
		VideoResolutionV540p,
		VideoResolutionV576p,
		VideoResolutionV720p,
		VideoResolutionV1080p,
		VideoResolutionV1440p,
		VideoResolutionV2160p,
		VideoResolutionV4320p,
	}
}

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

var _VideoResolutionValue = map[string]VideoResolution{
	"V360p":  VideoResolutionV360p,
	"v360p":  VideoResolutionV360p,
	"V480p":  VideoResolutionV480p,
	"v480p":  VideoResolutionV480p,
	"V540p":  VideoResolutionV540p,
	"v540p":  VideoResolutionV540p,
	"V576p":  VideoResolutionV576p,
	"v576p":  VideoResolutionV576p,
	"V720p":  VideoResolutionV720p,
	"v720p":  VideoResolutionV720p,
	"V1080p": VideoResolutionV1080p,
	"v1080p": VideoResolutionV1080p,
	"V1440p": VideoResolutionV1440p,
	"v1440p": VideoResolutionV1440p,
	"V2160p": VideoResolutionV2160p,
	"v2160p": VideoResolutionV2160p,
	"V4320p": VideoResolutionV4320p,
	"v4320p": VideoResolutionV4320p,
}

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

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

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

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

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

	return
}

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

type NullVideoResolution struct {
	VideoResolution VideoResolution
	Valid           bool
	Set             bool
}

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

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

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

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

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

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