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

// DeviceDataSourceAssociated device data source associated
//
// swagger:model DeviceDataSourceAssociated
type DeviceDataSourceAssociated struct {

	// description
	Description string `json:"description,omitempty"`

	// display name
	DisplayName string `json:"displayName,omitempty"`

	// has active instance
	HasActiveInstance bool `json:"hasActiveInstance,omitempty"`

	// has more
	HasMore int32 `json:"hasMore,omitempty"`

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

	// instance
	Instance []*DeviceDataSourceAssociatedInstance `json:"instance,omitempty"`

	// name
	Name string `json:"name,omitempty"`
}

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

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

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

func (m *DeviceDataSourceAssociated) validateInstance(formats strfmt.Registry) error {
	if swag.IsZero(m.Instance) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

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

func (m *DeviceDataSourceAssociated) contextValidateInstance(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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