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

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

// DeviceDataSourceInstanceConfig device data source instance config
//
// swagger:model DeviceDataSourceInstanceConfig
type DeviceDataSourceInstanceConfig struct {

	// alerts
	Alerts []*DeviceDataSourceInstanceConfigAlert `json:"alerts,omitempty"`

	// change status
	ChangeStatus string `json:"changeStatus,omitempty"`

	// config
	Config string `json:"config,omitempty"`

	// config err msg
	ConfigErrMsg string `json:"configErrMsg,omitempty"`

	// config status
	ConfigStatus int32 `json:"configStatus,omitempty"`

	// data source Id
	DataSourceID int32 `json:"dataSourceId,omitempty"`

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

	// delta config
	DeltaConfig []*DeviceDataSourceInstanceConfigDiff `json:"deltaConfig,omitempty"`

	// device data source Id
	DeviceDataSourceID int32 `json:"deviceDataSourceId,omitempty"`

	// device display name
	DeviceDisplayName string `json:"deviceDisplayName,omitempty"`

	// device Id
	DeviceID int32 `json:"deviceId,omitempty"`

	// id
	ID string `json:"id,omitempty"`

	// instance Id
	InstanceID int32 `json:"instanceId,omitempty"`

	// instance name
	InstanceName string `json:"instanceName,omitempty"`

	// poll timestamp
	PollTimestamp int64 `json:"pollTimestamp,omitempty"`

	// version
	Version int64 `json:"version,omitempty"`
}

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

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

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

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

func (m *DeviceDataSourceInstanceConfig) validateAlerts(formats strfmt.Registry) error {
	if swag.IsZero(m.Alerts) { // not required
		return nil
	}

	for i := 0; i < len(m.Alerts); i++ {
		if swag.IsZero(m.Alerts[i]) { // not required
			continue
		}

		if m.Alerts[i] != nil {
			if err := m.Alerts[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("alerts" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *DeviceDataSourceInstanceConfig) validateDeltaConfig(formats strfmt.Registry) error {
	if swag.IsZero(m.DeltaConfig) { // not required
		return nil
	}

	for i := 0; i < len(m.DeltaConfig); i++ {
		if swag.IsZero(m.DeltaConfig[i]) { // not required
			continue
		}

		if m.DeltaConfig[i] != nil {
			if err := m.DeltaConfig[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("deltaConfig" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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

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

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

func (m *DeviceDataSourceInstanceConfig) contextValidateAlerts(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Alerts); i++ {

		if m.Alerts[i] != nil {
			if err := m.Alerts[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("alerts" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *DeviceDataSourceInstanceConfig) contextValidateDeltaConfig(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.DeltaConfig); i++ {

		if m.DeltaConfig[i] != nil {
			if err := m.DeltaConfig[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("deltaConfig" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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