// Code generated by go-swagger; DO NOT EDIT.

package device_profile_service

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"encoding/json"
	"fmt"
	"io"

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

	"git.huangwc.com/pig/pig-farm-controller/internal/infra/transport/lora/chirp_stack_proto/models"
)

// DeviceProfileServiceUpdateReader is a Reader for the DeviceProfileServiceUpdate structure.
type DeviceProfileServiceUpdateReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *DeviceProfileServiceUpdateReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewDeviceProfileServiceUpdateOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	default:
		result := NewDeviceProfileServiceUpdateDefault(response.Code())
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		if response.Code()/100 == 2 {
			return result, nil
		}
		return nil, result
	}
}

// NewDeviceProfileServiceUpdateOK creates a DeviceProfileServiceUpdateOK with default headers values
func NewDeviceProfileServiceUpdateOK() *DeviceProfileServiceUpdateOK {
	return &DeviceProfileServiceUpdateOK{}
}

/*
DeviceProfileServiceUpdateOK describes a response with status code 200, with default header values.

A successful response.
*/
type DeviceProfileServiceUpdateOK struct {
	Payload interface{}
}

// IsSuccess returns true when this device profile service update o k response has a 2xx status code
func (o *DeviceProfileServiceUpdateOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this device profile service update o k response has a 3xx status code
func (o *DeviceProfileServiceUpdateOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this device profile service update o k response has a 4xx status code
func (o *DeviceProfileServiceUpdateOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this device profile service update o k response has a 5xx status code
func (o *DeviceProfileServiceUpdateOK) IsServerError() bool {
	return false
}

// IsCode returns true when this device profile service update o k response a status code equal to that given
func (o *DeviceProfileServiceUpdateOK) IsCode(code int) bool {
	return code == 200
}

// Code gets the status code for the device profile service update o k response
func (o *DeviceProfileServiceUpdateOK) Code() int {
	return 200
}

func (o *DeviceProfileServiceUpdateOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profiles/{deviceProfile.id}][%d] deviceProfileServiceUpdateOK %s", 200, payload)
}

func (o *DeviceProfileServiceUpdateOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profiles/{deviceProfile.id}][%d] deviceProfileServiceUpdateOK %s", 200, payload)
}

func (o *DeviceProfileServiceUpdateOK) GetPayload() interface{} {
	return o.Payload
}

func (o *DeviceProfileServiceUpdateOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	// response payload
	if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

// NewDeviceProfileServiceUpdateDefault creates a DeviceProfileServiceUpdateDefault with default headers values
func NewDeviceProfileServiceUpdateDefault(code int) *DeviceProfileServiceUpdateDefault {
	return &DeviceProfileServiceUpdateDefault{
		_statusCode: code,
	}
}

/*
DeviceProfileServiceUpdateDefault describes a response with status code -1, with default header values.

An unexpected error response.
*/
type DeviceProfileServiceUpdateDefault struct {
	_statusCode int

	Payload *models.RPCStatus
}

// IsSuccess returns true when this device profile service update default response has a 2xx status code
func (o *DeviceProfileServiceUpdateDefault) IsSuccess() bool {
	return o._statusCode/100 == 2
}

// IsRedirect returns true when this device profile service update default response has a 3xx status code
func (o *DeviceProfileServiceUpdateDefault) IsRedirect() bool {
	return o._statusCode/100 == 3
}

// IsClientError returns true when this device profile service update default response has a 4xx status code
func (o *DeviceProfileServiceUpdateDefault) IsClientError() bool {
	return o._statusCode/100 == 4
}

// IsServerError returns true when this device profile service update default response has a 5xx status code
func (o *DeviceProfileServiceUpdateDefault) IsServerError() bool {
	return o._statusCode/100 == 5
}

// IsCode returns true when this device profile service update default response a status code equal to that given
func (o *DeviceProfileServiceUpdateDefault) IsCode(code int) bool {
	return o._statusCode == code
}

// Code gets the status code for the device profile service update default response
func (o *DeviceProfileServiceUpdateDefault) Code() int {
	return o._statusCode
}

func (o *DeviceProfileServiceUpdateDefault) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profiles/{deviceProfile.id}][%d] DeviceProfileService_Update default %s", o._statusCode, payload)
}

func (o *DeviceProfileServiceUpdateDefault) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profiles/{deviceProfile.id}][%d] DeviceProfileService_Update default %s", o._statusCode, payload)
}

func (o *DeviceProfileServiceUpdateDefault) GetPayload() *models.RPCStatus {
	return o.Payload
}

func (o *DeviceProfileServiceUpdateDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	o.Payload = new(models.RPCStatus)

	// response payload
	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

/*
DeviceProfileServiceUpdateBody device profile service update body
swagger:model DeviceProfileServiceUpdateBody
*/
type DeviceProfileServiceUpdateBody struct {

	// device profile
	DeviceProfile *DeviceProfileServiceUpdateParamsBodyDeviceProfile `json:"deviceProfile,omitempty"`
}

// Validate validates this device profile service update body
func (o *DeviceProfileServiceUpdateBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (o *DeviceProfileServiceUpdateBody) validateDeviceProfile(formats strfmt.Registry) error {
	if swag.IsZero(o.DeviceProfile) { // not required
		return nil
	}

	if o.DeviceProfile != nil {
		if err := o.DeviceProfile.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this device profile service update body based on the context it is used
func (o *DeviceProfileServiceUpdateBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (o *DeviceProfileServiceUpdateBody) contextValidateDeviceProfile(ctx context.Context, formats strfmt.Registry) error {

	if o.DeviceProfile != nil {

		if swag.IsZero(o.DeviceProfile) { // not required
			return nil
		}

		if err := o.DeviceProfile.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile")
			}
			return err
		}
	}

	return nil
}

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

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

/*
DeviceProfileServiceUpdateParamsBodyDeviceProfile Device-profile object.
swagger:model DeviceProfileServiceUpdateParamsBodyDeviceProfile
*/
type DeviceProfileServiceUpdateParamsBodyDeviceProfile struct {

	// RX1 delay (for ABP).
	AbpRx1Delay int64 `json:"abpRx1Delay,omitempty"`

	// RX1 DR offset (for ABP).
	AbpRx1DrOffset int64 `json:"abpRx1DrOffset,omitempty"`

	// RX2 DR (for ABP).
	AbpRx2Dr int64 `json:"abpRx2Dr,omitempty"`

	// RX2 frequency (for ABP, Hz).
	AbpRx2Freq int64 `json:"abpRx2Freq,omitempty"`

	// ADR algorithm ID.
	AdrAlgorithmID string `json:"adrAlgorithmId,omitempty"`

	// Allow roaming.
	//
	// If set to true, it means that the device is allowed to use roaming.
	AllowRoaming bool `json:"allowRoaming,omitempty"`

	// Application Layer parameters.
	AppLayerParams *models.APIAppLayerParams `json:"appLayerParams,omitempty"`

	// Auto-detect measurements.
	// If set to true, measurements will be automatically added based on the
	// keys of the decoded payload. In cases where the decoded payload contains
	// random keys in the data, you want to set this to false.
	AutoDetectMeasurements bool `json:"autoDetectMeasurements,omitempty"`

	// Class-B ping-slot DR.
	ClassBPingSlotDr int64 `json:"classBPingSlotDr,omitempty"`

	// Class-B ping-slot freq (Hz).
	ClassBPingSlotFreq int64 `json:"classBPingSlotFreq,omitempty"`

	// Class-B ping-slot periodicity.
	// Valid options are: 0 - 7.
	//
	// Number of ping-slots per beacon-period:
	// pingNb = 2^(7-periodicity)
	//
	// Periodicity: 0 = 128 ping-slots per beacon period = ~ every 1 sec
	// Periodicity: 7 = 1 ping-slot per beacon period = ~ every 128 sec
	ClassBPingSlotPeriodicity int64 `json:"classBPingSlotPeriodicity,omitempty"`

	// Class-B timeout (seconds).
	// This is the maximum time ChirpStack will wait to receive an acknowledgement
	// from the device (if requested).
	ClassBTimeout int64 `json:"classBTimeout,omitempty"`

	// Class-C timeout (seconds).
	// This is the maximum time ChirpStack will wait to receive an acknowledgement
	// from the device (if requested).
	ClassCTimeout int64 `json:"classCTimeout,omitempty"`

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

	// Device-status request interval (times / day).
	// This defines the times per day that ChirpStack will request the
	// device-status from the device.
	DeviceStatusReqInterval int64 `json:"deviceStatusReqInterval,omitempty"`

	// Flush queue on device activation.
	FlushQueueOnActivate bool `json:"flushQueueOnActivate,omitempty"`

	// Device is a Relay device.
	// Enable this in case the device is a Relay. A Relay device implements TS011
	// and is able to relay data from relay capable devices.
	// See for more information the TS011 specification.
	IsRelay bool `json:"isRelay,omitempty"`

	// Device is a Relay end-device.
	// Enable this in case the device is an end-device that can operate under a
	// Relay. Please refer to the TS011 specification for more information.
	IsRelayEd bool `json:"isRelayEd,omitempty"`

	// LoRaWAN mac-version.
	MacVersion *models.CommonMacVersion `json:"macVersion,omitempty"`

	// Measurements.
	// If defined, ChirpStack will visualize these metrics in the web-interface.
	Measurements map[string]models.APIMeasurement `json:"measurements,omitempty"`

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

	// Payload codec runtime.
	PayloadCodecRuntime *models.APICodecRuntime `json:"payloadCodecRuntime,omitempty"`

	// Payload codec script.
	PayloadCodecScript string `json:"payloadCodecScript,omitempty"`

	// Regional parameters revision.
	RegParamsRevision *models.CommonRegParamsRevision `json:"regParamsRevision,omitempty"`

	// Region.
	Region *models.CommonRegion `json:"region,omitempty"`

	// Region configuration ID.
	// If set, devices will only use the associated region. If let blank, then
	// devices will use all regions matching the selected common-name. Note
	// that multiple region configurations can exist for the same common-name,
	// e.g. to provide an 8 channel and 16 channel configuration for the US915
	// band.
	RegionConfigID string `json:"regionConfigId,omitempty"`

	// Relay CAD periodicity.
	RelayCadPeriodicity *models.APICadPeriodicity `json:"relayCadPeriodicity,omitempty"`

	// Relay default channel index.
	// Valid values are 0 and 1, please refer to the RP002 specification for
	// the meaning of these values.
	RelayDefaultChannelIndex int64 `json:"relayDefaultChannelIndex,omitempty"`

	// Relay end-device activation mode.
	RelayEdActivationMode *models.APIRelayModeActivation `json:"relayEdActivationMode,omitempty"`

	// Relay end-device back-off (in case it does not receive WOR ACK frame).
	// 0 = Always send a LoRaWAN uplink
	// 1..63 = Send a LoRaWAN uplink after X WOR frames without a WOR ACK
	RelayEdBackOff int64 `json:"relayEdBackOff,omitempty"`

	// End-device only accept data through relay.
	// Only accept data for this device through a relay. This setting is useful
	// for testing as in case of a test-setup, the end-device is usually within
	// range of the gateway.
	RelayEdRelayOnly bool `json:"relayEdRelayOnly,omitempty"`

	// Relay end-device smart-enable level.
	RelayEdSmartEnableLevel int64 `json:"relayEdSmartEnableLevel,omitempty"`

	// Relay end-device uplink limit bucket size.
	//
	// This field indicates the multiplier to determine the bucket size
	// according to the following formula:
	// BucketSize TOKEN = _reload_rate x _bucket_size
	//
	// Valid values (0 - 3):
	//   0 = 1
	//   1 = 2
	//   2 = 4
	//   3 = 12
	RelayEdUplinkLimitBucketSize int64 `json:"relayEdUplinkLimitBucketSize,omitempty"`

	// Relay end-device uplink limit reload rate.
	//
	// Valid values:
	//   * 0 - 62 = X tokens every hour
	//   * 63     = no limitation
	RelayEdUplinkLimitReloadRate int64 `json:"relayEdUplinkLimitReloadRate,omitempty"`

	// Relay must be enabled.
	RelayEnabled bool `json:"relayEnabled,omitempty"`

	// Relay globak uplink limit bucket size.
	//
	// This field indicates the multiplier to determine the bucket size
	// according to the following formula:
	// BucketSize TOKEN = _reload_rate x _bucket_size
	//
	// Valid values (0 - 3):
	//   0 = 1
	//   1 = 2
	//   2 = 4
	//   3 = 12
	RelayGlobalUplinkLimitBucketSize int64 `json:"relayGlobalUplinkLimitBucketSize,omitempty"`

	// Relay global uplink limit reload rate.
	//
	// Valid values:
	//   * 0 - 126 = X tokens every hour
	//   * 127     = no limitation
	RelayGlobalUplinkLimitReloadRate int64 `json:"relayGlobalUplinkLimitReloadRate,omitempty"`

	// Relay join-request limit bucket size.
	//
	// This field indicates the multiplier to determine the bucket size
	// according to the following formula:
	// BucketSize TOKEN = _reload_rate x _bucket_size
	//
	// Valid values (0 - 3):
	//   0 = 1
	//   1 = 2
	//   2 = 4
	//   3 = 12
	RelayJoinReqLimitBucketSize int64 `json:"relayJoinReqLimitBucketSize,omitempty"`

	// Relay join-request limit reload rate.
	//
	// Valid values:
	//   * 0 - 126 = X tokens every hour
	//   * 127     = no limitation
	RelayJoinReqLimitReloadRate int64 `json:"relayJoinReqLimitReloadRate,omitempty"`

	// Relay notify limit bucket size.
	//
	// This field indicates the multiplier to determine the bucket size
	// according to the following formula:
	// BucketSize TOKEN = _reload_rate x _bucket_size
	//
	// Valid values (0 - 3):
	//   0 = 1
	//   1 = 2
	//   2 = 4
	//   3 = 12
	RelayNotifyLimitBucketSize int64 `json:"relayNotifyLimitBucketSize,omitempty"`

	// Relay notify limit reload rate.
	//
	// Valid values:
	//   * 0 - 126 = X tokens every hour
	//   * 127     = no limitation
	RelayNotifyLimitReloadRate int64 `json:"relayNotifyLimitReloadRate,omitempty"`

	// Relay overall limit bucket size.
	//
	// This field indicates the multiplier to determine the bucket size
	// according to the following formula:
	// BucketSize TOKEN = _reload_rate x _bucket_size
	//
	// Valid values (0 - 3):
	//   0 = 1
	//   1 = 2
	//   2 = 4
	//   3 = 12
	RelayOverallLimitBucketSize int64 `json:"relayOverallLimitBucketSize,omitempty"`

	// Relay overall limit reload rate.
	//
	// Valid values:
	//   * 0 - 126 = X tokens every hour
	//   * 127     = no limitation
	RelayOverallLimitReloadRate int64 `json:"relayOverallLimitReloadRate,omitempty"`

	// Relay second channel ACK offset.
	RelaySecondChannelAckOffset *models.APISecondChAckOffset `json:"relaySecondChannelAckOffset,omitempty"`

	// Relay second channel DR.
	RelaySecondChannelDr int64 `json:"relaySecondChannelDr,omitempty"`

	// Relay second channel frequency (Hz).
	RelaySecondChannelFreq int64 `json:"relaySecondChannelFreq,omitempty"`

	// RX1 Delay.
	//
	// This makes it possible to override the system RX1 Delay. Please note that
	// this values only has effect in case it is higher than the system value.
	// In other words, it can be used to increase the RX1 Delay but not to decrease
	// it.
	// Valid options are 1 - 15 (0 = always use system RX1 Delay).
	Rx1Delay int64 `json:"rx1Delay,omitempty"`

	// Supports Class B.
	SupportsClassB bool `json:"supportsClassB,omitempty"`

	// Supports Class-C.
	SupportsClassC bool `json:"supportsClassC,omitempty"`

	// Supports OTAA.
	SupportsOtaa bool `json:"supportsOtaa,omitempty"`

	// Tags (user defined).
	// These tags can be used to add additional information the the
	// device-profile. These tags are exposed in all the integration events of
	// devices using this device-profile.
	Tags map[string]string `json:"tags,omitempty"`

	// Tenant ID (UUID).
	TenantID string `json:"tenantId,omitempty"`

	// Uplink interval (seconds).
	// This defines the expected uplink interval which the device uses for
	// communication. If the uplink interval has expired and no uplink has
	// been received, the device is considered inactive.
	UplinkInterval int64 `json:"uplinkInterval,omitempty"`
}

// Validate validates this device profile service update params body device profile
func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateAppLayerParams(formats strfmt.Registry) error {
	if swag.IsZero(o.AppLayerParams) { // not required
		return nil
	}

	if o.AppLayerParams != nil {
		if err := o.AppLayerParams.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "appLayerParams")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "appLayerParams")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateMacVersion(formats strfmt.Registry) error {
	if swag.IsZero(o.MacVersion) { // not required
		return nil
	}

	if o.MacVersion != nil {
		if err := o.MacVersion.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "macVersion")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "macVersion")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateMeasurements(formats strfmt.Registry) error {
	if swag.IsZero(o.Measurements) { // not required
		return nil
	}

	for k := range o.Measurements {

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

	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validatePayloadCodecRuntime(formats strfmt.Registry) error {
	if swag.IsZero(o.PayloadCodecRuntime) { // not required
		return nil
	}

	if o.PayloadCodecRuntime != nil {
		if err := o.PayloadCodecRuntime.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "payloadCodecRuntime")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "payloadCodecRuntime")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateRegParamsRevision(formats strfmt.Registry) error {
	if swag.IsZero(o.RegParamsRevision) { // not required
		return nil
	}

	if o.RegParamsRevision != nil {
		if err := o.RegParamsRevision.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "regParamsRevision")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "regParamsRevision")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateRegion(formats strfmt.Registry) error {
	if swag.IsZero(o.Region) { // not required
		return nil
	}

	if o.Region != nil {
		if err := o.Region.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "region")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "region")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateRelayCadPeriodicity(formats strfmt.Registry) error {
	if swag.IsZero(o.RelayCadPeriodicity) { // not required
		return nil
	}

	if o.RelayCadPeriodicity != nil {
		if err := o.RelayCadPeriodicity.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "relayCadPeriodicity")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "relayCadPeriodicity")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateRelayEdActivationMode(formats strfmt.Registry) error {
	if swag.IsZero(o.RelayEdActivationMode) { // not required
		return nil
	}

	if o.RelayEdActivationMode != nil {
		if err := o.RelayEdActivationMode.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "relayEdActivationMode")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "relayEdActivationMode")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) validateRelaySecondChannelAckOffset(formats strfmt.Registry) error {
	if swag.IsZero(o.RelaySecondChannelAckOffset) { // not required
		return nil
	}

	if o.RelaySecondChannelAckOffset != nil {
		if err := o.RelaySecondChannelAckOffset.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "relaySecondChannelAckOffset")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "relaySecondChannelAckOffset")
			}
			return err
		}
	}

	return nil
}

// ContextValidate validate this device profile service update params body device profile based on the context it is used
func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateAppLayerParams(ctx context.Context, formats strfmt.Registry) error {

	if o.AppLayerParams != nil {

		if swag.IsZero(o.AppLayerParams) { // not required
			return nil
		}

		if err := o.AppLayerParams.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "appLayerParams")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "appLayerParams")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateMacVersion(ctx context.Context, formats strfmt.Registry) error {

	if o.MacVersion != nil {

		if swag.IsZero(o.MacVersion) { // not required
			return nil
		}

		if err := o.MacVersion.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "macVersion")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "macVersion")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateMeasurements(ctx context.Context, formats strfmt.Registry) error {

	for k := range o.Measurements {

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

	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidatePayloadCodecRuntime(ctx context.Context, formats strfmt.Registry) error {

	if o.PayloadCodecRuntime != nil {

		if swag.IsZero(o.PayloadCodecRuntime) { // not required
			return nil
		}

		if err := o.PayloadCodecRuntime.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "payloadCodecRuntime")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "payloadCodecRuntime")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateRegParamsRevision(ctx context.Context, formats strfmt.Registry) error {

	if o.RegParamsRevision != nil {

		if swag.IsZero(o.RegParamsRevision) { // not required
			return nil
		}

		if err := o.RegParamsRevision.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "regParamsRevision")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "regParamsRevision")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateRegion(ctx context.Context, formats strfmt.Registry) error {

	if o.Region != nil {

		if swag.IsZero(o.Region) { // not required
			return nil
		}

		if err := o.Region.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "region")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "region")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateRelayCadPeriodicity(ctx context.Context, formats strfmt.Registry) error {

	if o.RelayCadPeriodicity != nil {

		if swag.IsZero(o.RelayCadPeriodicity) { // not required
			return nil
		}

		if err := o.RelayCadPeriodicity.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "relayCadPeriodicity")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "relayCadPeriodicity")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateRelayEdActivationMode(ctx context.Context, formats strfmt.Registry) error {

	if o.RelayEdActivationMode != nil {

		if swag.IsZero(o.RelayEdActivationMode) { // not required
			return nil
		}

		if err := o.RelayEdActivationMode.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "relayEdActivationMode")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "relayEdActivationMode")
			}
			return err
		}
	}

	return nil
}

func (o *DeviceProfileServiceUpdateParamsBodyDeviceProfile) contextValidateRelaySecondChannelAckOffset(ctx context.Context, formats strfmt.Registry) error {

	if o.RelaySecondChannelAckOffset != nil {

		if swag.IsZero(o.RelaySecondChannelAckOffset) { // not required
			return nil
		}

		if err := o.RelaySecondChannelAckOffset.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("body" + "." + "deviceProfile" + "." + "relaySecondChannelAckOffset")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "deviceProfile" + "." + "relaySecondChannelAckOffset")
			}
			return err
		}
	}

	return nil
}

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

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