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

// CustomFlexibleVirtualDataSourceEx custom flexible virtual data source ex
//
// swagger:model CustomFlexibleVirtualDataSourceEx
type CustomFlexibleVirtualDataSourceEx struct {

	// aggregate function
	AggregateFunction string `json:"aggregateFunction,omitempty"`

	// consolidate function
	ConsolidateFunction string `json:"consolidateFunction,omitempty"`

	// custom graph Id
	// Read Only: true
	CustomGraphID int32 `json:"customGraphId,omitempty"`

	// data point Id
	DataPointID int32 `json:"dataPointId,omitempty"`

	// data point name
	DataPointName string `json:"dataPointName,omitempty"`

	// data source full name
	DataSourceFullName string `json:"dataSourceFullName,omitempty"`

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

	// device display name
	// Required: true
	DeviceDisplayName *GlobMatchToggle `json:"deviceDisplayName"`

	// device group full path
	// Required: true
	DeviceGroupFullPath *GlobMatchToggle `json:"deviceGroupFullPath"`

	// display
	// Required: true
	Display *GraphDisplay `json:"display"`

	// id
	// Read Only: true
	ID int32 `json:"id,omitempty"`

	// instance name
	// Required: true
	InstanceName *GlobMatchToggle `json:"instanceName"`

	// name
	// Required: true
	Name *string `json:"name"`
}

// Validate validates this custom flexible virtual data source ex
func (m *CustomFlexibleVirtualDataSourceEx) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *CustomFlexibleVirtualDataSourceEx) validateDeviceDisplayName(formats strfmt.Registry) error {

	if err := validate.Required("deviceDisplayName", "body", m.DeviceDisplayName); err != nil {
		return err
	}

	if m.DeviceDisplayName != nil {
		if err := m.DeviceDisplayName.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("deviceDisplayName")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) validateDeviceGroupFullPath(formats strfmt.Registry) error {

	if err := validate.Required("deviceGroupFullPath", "body", m.DeviceGroupFullPath); err != nil {
		return err
	}

	if m.DeviceGroupFullPath != nil {
		if err := m.DeviceGroupFullPath.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("deviceGroupFullPath")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) validateDisplay(formats strfmt.Registry) error {

	if err := validate.Required("display", "body", m.Display); err != nil {
		return err
	}

	if m.Display != nil {
		if err := m.Display.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("display")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) validateInstanceName(formats strfmt.Registry) error {

	if err := validate.Required("instanceName", "body", m.InstanceName); err != nil {
		return err
	}

	if m.InstanceName != nil {
		if err := m.InstanceName.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("instanceName")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) validateName(formats strfmt.Registry) error {

	if err := validate.Required("name", "body", m.Name); err != nil {
		return err
	}

	return nil
}

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

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

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

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

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

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

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

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

func (m *CustomFlexibleVirtualDataSourceEx) contextValidateCustomGraphID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) contextValidateDeviceDisplayName(ctx context.Context, formats strfmt.Registry) error {

	if m.DeviceDisplayName != nil {
		if err := m.DeviceDisplayName.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("deviceDisplayName")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) contextValidateDeviceGroupFullPath(ctx context.Context, formats strfmt.Registry) error {

	if m.DeviceGroupFullPath != nil {
		if err := m.DeviceGroupFullPath.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("deviceGroupFullPath")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) contextValidateDisplay(ctx context.Context, formats strfmt.Registry) error {

	if m.Display != nil {
		if err := m.Display.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("display")
			}
			return err
		}
	}

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *CustomFlexibleVirtualDataSourceEx) contextValidateInstanceName(ctx context.Context, formats strfmt.Registry) error {

	if m.InstanceName != nil {
		if err := m.InstanceName.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("instanceName")
			}
			return err
		}
	}

	return nil
}

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

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