// 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 (
	"context"

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

// APIGetDeviceMetricsResponse api get device metrics response
//
// swagger:model apiGetDeviceMetricsResponse
type APIGetDeviceMetricsResponse struct {

	// metrics
	Metrics map[string]CommonMetric `json:"metrics,omitempty"`

	// states
	States map[string]APIDeviceState `json:"states,omitempty"`
}

// Validate validates this api get device metrics response
func (m *APIGetDeviceMetricsResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *APIGetDeviceMetricsResponse) validateMetrics(formats strfmt.Registry) error {
	if swag.IsZero(m.Metrics) { // not required
		return nil
	}

	for k := range m.Metrics {

		if err := validate.Required("metrics"+"."+k, "body", m.Metrics[k]); err != nil {
			return err
		}
		if val, ok := m.Metrics[k]; ok {
			if err := val.Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("metrics" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("metrics" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

func (m *APIGetDeviceMetricsResponse) validateStates(formats strfmt.Registry) error {
	if swag.IsZero(m.States) { // not required
		return nil
	}

	for k := range m.States {

		if err := validate.Required("states"+"."+k, "body", m.States[k]); err != nil {
			return err
		}
		if val, ok := m.States[k]; ok {
			if err := val.Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("states" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("states" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this api get device metrics response based on the context it is used
func (m *APIGetDeviceMetricsResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *APIGetDeviceMetricsResponse) contextValidateMetrics(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.Metrics {

		if val, ok := m.Metrics[k]; ok {
			if err := val.ContextValidate(ctx, formats); err != nil {
				return err
			}
		}

	}

	return nil
}

func (m *APIGetDeviceMetricsResponse) contextValidateStates(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.States {

		if val, ok := m.States[k]; ok {
			if err := val.ContextValidate(ctx, formats); err != nil {
				return err
			}
		}

	}

	return nil
}

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

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