// 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"
)

// DeviceDataSourceData device data source data
//
// swagger:model DeviceDataSourceData
type DeviceDataSourceData struct {

	// data points
	// Read Only: true
	DataPoints []string `json:"dataPoints,omitempty"`

	// data source name
	// Read Only: true
	DataSourceName string `json:"dataSourceName,omitempty"`

	// instances
	// Read Only: true
	Instances map[string]RawDataValues `json:"instances,omitempty"`

	// next page params
	// Read Only: true
	NextPageParams string `json:"nextPageParams,omitempty"`
}

// Validate validates this device data source data
func (m *DeviceDataSourceData) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *DeviceDataSourceData) validateInstances(formats strfmt.Registry) error {
	if swag.IsZero(m.Instances) { // not required
		return nil
	}

	for k := range m.Instances {

		if err := validate.Required("instances"+"."+k, "body", m.Instances[k]); err != nil {
			return err
		}
		if val, ok := m.Instances[k]; ok {
			if err := val.Validate(formats); err != nil {
				return err
			}
		}

	}

	return nil
}

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

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

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

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

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

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

func (m *DeviceDataSourceData) contextValidateDataPoints(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "dataPoints", "body", []string(m.DataPoints)); err != nil {
		return err
	}

	return nil
}

func (m *DeviceDataSourceData) contextValidateDataSourceName(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *DeviceDataSourceData) contextValidateInstances(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.Instances {

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

	}

	return nil
}

func (m *DeviceDataSourceData) contextValidateNextPageParams(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

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

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