// Code generated by go-swagger; DO NOT EDIT.

package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"bytes"
	"context"
	"encoding/json"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// GaugeWidgetData gauge widget data
//
// swagger:model GaugeWidgetData
type GaugeWidgetData struct {
	titleField string

	// color level
	// Read Only: true
	ColorLevel int32 `json:"colorLevel,omitempty"`

	// current value
	// Read Only: true
	CurrentValue float64 `json:"currentValue,omitempty"`

	// display type
	DisplayType int32 `json:"displayType,omitempty"`

	// display unit
	DisplayUnit string `json:"displayUnit,omitempty"`

	// history timestamps
	// Read Only: true
	HistoryTimestamps []int64 `json:"historyTimestamps,omitempty"`

	// history values
	// Read Only: true
	HistoryValues interface{} `json:"historyValues,omitempty"`

	// legend
	// Read Only: true
	Legend string `json:"legend,omitempty"`

	// max value
	// Read Only: true
	MaxValue float64 `json:"maxValue,omitempty"`

	// min value
	// Read Only: true
	MinValue float64 `json:"minValue,omitempty"`

	// peak time
	// Read Only: true
	PeakTime int64 `json:"peakTime,omitempty"`

	// peak time on local
	// Read Only: true
	PeakTimeOnLocal string `json:"peakTimeOnLocal,omitempty"`

	// peak value
	// Read Only: true
	PeakValue float64 `json:"peakValue,omitempty"`

	// show peak
	// Read Only: true
	ShowPeak *bool `json:"showPeak,omitempty"`
}

// Title gets the title of this subtype
func (m *GaugeWidgetData) Title() string {
	return m.titleField
}

// SetTitle sets the title of this subtype
func (m *GaugeWidgetData) SetTitle(val string) {
	m.titleField = val
}

// Type gets the type of this subtype
func (m *GaugeWidgetData) Type() string {
	return "gauge"
}

// SetType sets the type of this subtype
func (m *GaugeWidgetData) SetType(val string) {
}

// UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
func (m *GaugeWidgetData) UnmarshalJSON(raw []byte) error {
	var data struct {

		// color level
		// Read Only: true
		ColorLevel int32 `json:"colorLevel,omitempty"`

		// current value
		// Read Only: true
		CurrentValue float64 `json:"currentValue,omitempty"`

		// display type
		DisplayType int32 `json:"displayType,omitempty"`

		// display unit
		DisplayUnit string `json:"displayUnit,omitempty"`

		// history timestamps
		// Read Only: true
		HistoryTimestamps []int64 `json:"historyTimestamps,omitempty"`

		// history values
		// Read Only: true
		HistoryValues interface{} `json:"historyValues,omitempty"`

		// legend
		// Read Only: true
		Legend string `json:"legend,omitempty"`

		// max value
		// Read Only: true
		MaxValue float64 `json:"maxValue,omitempty"`

		// min value
		// Read Only: true
		MinValue float64 `json:"minValue,omitempty"`

		// peak time
		// Read Only: true
		PeakTime int64 `json:"peakTime,omitempty"`

		// peak time on local
		// Read Only: true
		PeakTimeOnLocal string `json:"peakTimeOnLocal,omitempty"`

		// peak value
		// Read Only: true
		PeakValue float64 `json:"peakValue,omitempty"`

		// show peak
		// Read Only: true
		ShowPeak *bool `json:"showPeak,omitempty"`
	}
	buf := bytes.NewBuffer(raw)
	dec := json.NewDecoder(buf)
	dec.UseNumber()

	if err := dec.Decode(&data); err != nil {
		return err
	}

	var base struct {
		/* Just the base type fields. Used for unmashalling polymorphic types.*/

		Title string `json:"title,omitempty"`

		Type string `json:"type,omitempty"`
	}
	buf = bytes.NewBuffer(raw)
	dec = json.NewDecoder(buf)
	dec.UseNumber()

	if err := dec.Decode(&base); err != nil {
		return err
	}

	var result GaugeWidgetData

	result.titleField = base.Title

	if base.Type != result.Type() {
		/* Not the type we're looking for. */
		return errors.New(422, "invalid type value: %q", base.Type)
	}

	result.ColorLevel = data.ColorLevel
	result.CurrentValue = data.CurrentValue
	result.DisplayType = data.DisplayType
	result.DisplayUnit = data.DisplayUnit
	result.HistoryTimestamps = data.HistoryTimestamps
	result.HistoryValues = data.HistoryValues
	result.Legend = data.Legend
	result.MaxValue = data.MaxValue
	result.MinValue = data.MinValue
	result.PeakTime = data.PeakTime
	result.PeakTimeOnLocal = data.PeakTimeOnLocal
	result.PeakValue = data.PeakValue
	result.ShowPeak = data.ShowPeak

	*m = result

	return nil
}

// MarshalJSON marshals this object with a polymorphic type to a JSON structure
func (m GaugeWidgetData) MarshalJSON() ([]byte, error) {
	var b1, b2, b3 []byte
	var err error
	b1, err = json.Marshal(struct {

		// color level
		// Read Only: true
		ColorLevel int32 `json:"colorLevel,omitempty"`

		// current value
		// Read Only: true
		CurrentValue float64 `json:"currentValue,omitempty"`

		// display type
		DisplayType int32 `json:"displayType,omitempty"`

		// display unit
		DisplayUnit string `json:"displayUnit,omitempty"`

		// history timestamps
		// Read Only: true
		HistoryTimestamps []int64 `json:"historyTimestamps,omitempty"`

		// history values
		// Read Only: true
		HistoryValues interface{} `json:"historyValues,omitempty"`

		// legend
		// Read Only: true
		Legend string `json:"legend,omitempty"`

		// max value
		// Read Only: true
		MaxValue float64 `json:"maxValue,omitempty"`

		// min value
		// Read Only: true
		MinValue float64 `json:"minValue,omitempty"`

		// peak time
		// Read Only: true
		PeakTime int64 `json:"peakTime,omitempty"`

		// peak time on local
		// Read Only: true
		PeakTimeOnLocal string `json:"peakTimeOnLocal,omitempty"`

		// peak value
		// Read Only: true
		PeakValue float64 `json:"peakValue,omitempty"`

		// show peak
		// Read Only: true
		ShowPeak *bool `json:"showPeak,omitempty"`
	}{

		ColorLevel: m.ColorLevel,

		CurrentValue: m.CurrentValue,

		DisplayType: m.DisplayType,

		DisplayUnit: m.DisplayUnit,

		HistoryTimestamps: m.HistoryTimestamps,

		HistoryValues: m.HistoryValues,

		Legend: m.Legend,

		MaxValue: m.MaxValue,

		MinValue: m.MinValue,

		PeakTime: m.PeakTime,

		PeakTimeOnLocal: m.PeakTimeOnLocal,

		PeakValue: m.PeakValue,

		ShowPeak: m.ShowPeak,
	})
	if err != nil {
		return nil, err
	}
	b2, err = json.Marshal(struct {
		Title string `json:"title,omitempty"`

		Type string `json:"type,omitempty"`
	}{

		Title: m.Title(),

		Type: m.Type(),
	})
	if err != nil {
		return nil, err
	}

	return swag.ConcatJSON(b1, b2, b3), nil
}

// Validate validates this gauge widget data
func (m *GaugeWidgetData) Validate(formats strfmt.Registry) error {
	var res []error

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

// ContextValidate validate this gauge widget data based on the context it is used
func (m *GaugeWidgetData) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := m.contextValidateColorLevel(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateCurrentValue(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateHistoryTimestamps(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateLegend(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateMaxValue(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateMinValue(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidatePeakTime(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidatePeakTimeOnLocal(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidatePeakValue(ctx, formats); err != nil {
		res = append(res, err)
	}

	if err := m.contextValidateShowPeak(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (m *GaugeWidgetData) contextValidateType(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "type", "body", string(m.Type())); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateColorLevel(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "colorLevel", "body", int32(m.ColorLevel)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateCurrentValue(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "currentValue", "body", float64(m.CurrentValue)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateHistoryTimestamps(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "historyTimestamps", "body", []int64(m.HistoryTimestamps)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateLegend(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "legend", "body", string(m.Legend)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateMaxValue(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "maxValue", "body", float64(m.MaxValue)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateMinValue(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "minValue", "body", float64(m.MinValue)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidatePeakTime(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "peakTime", "body", int64(m.PeakTime)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidatePeakTimeOnLocal(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "peakTimeOnLocal", "body", string(m.PeakTimeOnLocal)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidatePeakValue(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "peakValue", "body", float64(m.PeakValue)); err != nil {
		return err
	}

	return nil
}

func (m *GaugeWidgetData) contextValidateShowPeak(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "showPeak", "body", m.ShowPeak); err != nil {
		return err
	}

	return nil
}

// MarshalBinary interface implementation
func (m *GaugeWidgetData) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *GaugeWidgetData) UnmarshalBinary(b []byte) error {
	var res GaugeWidgetData
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
