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

// APIDeviceProfile api device profile
//
// swagger:model apiDeviceProfile
type APIDeviceProfile 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 *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-profile ID (UUID).
	// Note: on create this will be automatically generated.
	ID string `json:"id,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 *CommonMacVersion `json:"macVersion,omitempty"`

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

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

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

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

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

	// Region.
	Region *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 *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 *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 *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 api device profile
func (m *APIDeviceProfile) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

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

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

	return nil
}

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

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

	return nil
}

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

	for k := range m.Measurements {

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

	}

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

	return nil
}

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

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

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

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

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

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

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

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

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

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

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

func (m *APIDeviceProfile) contextValidateAppLayerParams(ctx context.Context, formats strfmt.Registry) error {

	if m.AppLayerParams != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateMacVersion(ctx context.Context, formats strfmt.Registry) error {

	if m.MacVersion != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateMeasurements(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.Measurements {

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

	}

	return nil
}

func (m *APIDeviceProfile) contextValidatePayloadCodecRuntime(ctx context.Context, formats strfmt.Registry) error {

	if m.PayloadCodecRuntime != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateRegParamsRevision(ctx context.Context, formats strfmt.Registry) error {

	if m.RegParamsRevision != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateRegion(ctx context.Context, formats strfmt.Registry) error {

	if m.Region != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateRelayCadPeriodicity(ctx context.Context, formats strfmt.Registry) error {

	if m.RelayCadPeriodicity != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateRelayEdActivationMode(ctx context.Context, formats strfmt.Registry) error {

	if m.RelayEdActivationMode != nil {

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

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

	return nil
}

func (m *APIDeviceProfile) contextValidateRelaySecondChannelAckOffset(ctx context.Context, formats strfmt.Registry) error {

	if m.RelaySecondChannelAckOffset != nil {

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

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

	return nil
}

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

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