// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.

package components

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/LukeHagar/plexgo/internal/utils"
)

// Type - The type of the value of this setting
type Type string

const (
	TypeBool   Type = "bool"
	TypeInt    Type = "int"
	TypeText   Type = "text"
	TypeDouble Type = "double"
)

func (e Type) ToPointer() *Type {
	return &e
}
func (e *Type) UnmarshalJSON(data []byte) error {
	var v string
	if err := json.Unmarshal(data, &v); err != nil {
		return err
	}
	switch v {
	case "bool":
		fallthrough
	case "int":
		fallthrough
	case "text":
		fallthrough
	case "double":
		*e = Type(v)
		return nil
	default:
		return fmt.Errorf("invalid value for Type: %v", v)
	}
}

type DefaultType string

const (
	DefaultTypeStr     DefaultType = "str"
	DefaultTypeNumber  DefaultType = "number"
	DefaultTypeBoolean DefaultType = "boolean"
)

// Default - The default value of this setting
type Default struct {
	Str     *string  `queryParam:"inline,name=default"`
	Number  *float64 `queryParam:"inline,name=default"`
	Boolean *bool    `queryParam:"inline,name=default"`

	Type DefaultType
}

func CreateDefaultStr(str string) Default {
	typ := DefaultTypeStr

	return Default{
		Str:  &str,
		Type: typ,
	}
}

func CreateDefaultNumber(number float64) Default {
	typ := DefaultTypeNumber

	return Default{
		Number: &number,
		Type:   typ,
	}
}

func CreateDefaultBoolean(boolean bool) Default {
	typ := DefaultTypeBoolean

	return Default{
		Boolean: &boolean,
		Type:    typ,
	}
}

func (u *Default) UnmarshalJSON(data []byte) error {

	var str string = ""
	if err := utils.UnmarshalJSON(data, &str, "", true, nil); err == nil {
		u.Str = &str
		u.Type = DefaultTypeStr
		return nil
	}

	var number float64 = float64(0)
	if err := utils.UnmarshalJSON(data, &number, "", true, nil); err == nil {
		u.Number = &number
		u.Type = DefaultTypeNumber
		return nil
	}

	var boolean bool = false
	if err := utils.UnmarshalJSON(data, &boolean, "", true, nil); err == nil {
		u.Boolean = &boolean
		u.Type = DefaultTypeBoolean
		return nil
	}

	return fmt.Errorf("could not unmarshal `%s` into any supported union types for Default", string(data))
}

func (u Default) MarshalJSON() ([]byte, error) {
	if u.Str != nil {
		return utils.MarshalJSON(u.Str, "", true)
	}

	if u.Number != nil {
		return utils.MarshalJSON(u.Number, "", true)
	}

	if u.Boolean != nil {
		return utils.MarshalJSON(u.Boolean, "", true)
	}

	return nil, errors.New("could not marshal union type Default: all fields are null")
}

type ValueType string

const (
	ValueTypeStr     ValueType = "str"
	ValueTypeNumber  ValueType = "number"
	ValueTypeBoolean ValueType = "boolean"
)

// Value - The current value of this setting
type Value struct {
	Str     *string  `queryParam:"inline,name=value"`
	Number  *float64 `queryParam:"inline,name=value"`
	Boolean *bool    `queryParam:"inline,name=value"`

	Type ValueType
}

func CreateValueStr(str string) Value {
	typ := ValueTypeStr

	return Value{
		Str:  &str,
		Type: typ,
	}
}

func CreateValueNumber(number float64) Value {
	typ := ValueTypeNumber

	return Value{
		Number: &number,
		Type:   typ,
	}
}

func CreateValueBoolean(boolean bool) Value {
	typ := ValueTypeBoolean

	return Value{
		Boolean: &boolean,
		Type:    typ,
	}
}

func (u *Value) UnmarshalJSON(data []byte) error {

	var str string = ""
	if err := utils.UnmarshalJSON(data, &str, "", true, nil); err == nil {
		u.Str = &str
		u.Type = ValueTypeStr
		return nil
	}

	var number float64 = float64(0)
	if err := utils.UnmarshalJSON(data, &number, "", true, nil); err == nil {
		u.Number = &number
		u.Type = ValueTypeNumber
		return nil
	}

	var boolean bool = false
	if err := utils.UnmarshalJSON(data, &boolean, "", true, nil); err == nil {
		u.Boolean = &boolean
		u.Type = ValueTypeBoolean
		return nil
	}

	return fmt.Errorf("could not unmarshal `%s` into any supported union types for Value", string(data))
}

func (u Value) MarshalJSON() ([]byte, error) {
	if u.Str != nil {
		return utils.MarshalJSON(u.Str, "", true)
	}

	if u.Number != nil {
		return utils.MarshalJSON(u.Number, "", true)
	}

	if u.Boolean != nil {
		return utils.MarshalJSON(u.Boolean, "", true)
	}

	return nil, errors.New("could not marshal union type Value: all fields are null")
}

// Setting - A configuration setting or preference
type Setting struct {
	// The type of the value of this setting
	Type *Type `json:"type,omitempty"`
	// The default value of this setting
	Default *Default `json:"default,omitempty"`
	// Whether the setting is considered advanced and normally hidden from the user
	Advanced *bool `json:"advanced,omitempty"`
	// The possible values for this setting if restricted. The list is `|` separated with `value:name` entries.
	EnumValues *string `json:"enumValues,omitempty"`
	// The group name of this setting to aid in display of a hierarchy
	Group *string `json:"group,omitempty"`
	// Whether the setting is hidden or not
	Hidden *bool `json:"hidden,omitempty"`
	// The query parameter name for this setting
	ID *string `json:"id,omitempty"`
	// A user-friendly name for the setting
	Label *string `json:"label,omitempty"`
	// A description of the setting
	Summary *string `json:"summary,omitempty"`
	// The current value of this setting
	Value *Value `json:"value,omitempty"`
}

func (s *Setting) GetType() *Type {
	if s == nil {
		return nil
	}
	return s.Type
}

func (s *Setting) GetDefault() *Default {
	if s == nil {
		return nil
	}
	return s.Default
}

func (s *Setting) GetAdvanced() *bool {
	if s == nil {
		return nil
	}
	return s.Advanced
}

func (s *Setting) GetEnumValues() *string {
	if s == nil {
		return nil
	}
	return s.EnumValues
}

func (s *Setting) GetGroup() *string {
	if s == nil {
		return nil
	}
	return s.Group
}

func (s *Setting) GetHidden() *bool {
	if s == nil {
		return nil
	}
	return s.Hidden
}

func (s *Setting) GetID() *string {
	if s == nil {
		return nil
	}
	return s.ID
}

func (s *Setting) GetLabel() *string {
	if s == nil {
		return nil
	}
	return s.Label
}

func (s *Setting) GetSummary() *string {
	if s == nil {
		return nil
	}
	return s.Summary
}

func (s *Setting) GetValue() *Value {
	if s == nil {
		return nil
	}
	return s.Value
}
