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

// APIGetDeviceLinkMetricsResponse api get device link metrics response
//
// swagger:model apiGetDeviceLinkMetricsResponse
type APIGetDeviceLinkMetricsResponse struct {

	// Errors.
	Errors *CommonMetric `json:"errors,omitempty"`

	// RSSI (as reported by the gateway(s)).
	GwRssi *CommonMetric `json:"gwRssi,omitempty"`

	// SNR (as reported by the gateway(s)).
	GwSnr *CommonMetric `json:"gwSnr,omitempty"`

	// Packets received from the device.
	RxPackets *CommonMetric `json:"rxPackets,omitempty"`

	// Packets received by DR.
	RxPacketsPerDr *CommonMetric `json:"rxPacketsPerDr,omitempty"`

	// Packets received by frequency.
	RxPacketsPerFreq *CommonMetric `json:"rxPacketsPerFreq,omitempty"`
}

// Validate validates this api get device link metrics response
func (m *APIGetDeviceLinkMetricsResponse) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

func (m *APIGetDeviceLinkMetricsResponse) validateErrors(formats strfmt.Registry) error {
	if swag.IsZero(m.Errors) { // not required
		return nil
	}

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) validateGwRssi(formats strfmt.Registry) error {
	if swag.IsZero(m.GwRssi) { // not required
		return nil
	}

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) validateGwSnr(formats strfmt.Registry) error {
	if swag.IsZero(m.GwSnr) { // not required
		return nil
	}

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) validateRxPackets(formats strfmt.Registry) error {
	if swag.IsZero(m.RxPackets) { // not required
		return nil
	}

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) validateRxPacketsPerDr(formats strfmt.Registry) error {
	if swag.IsZero(m.RxPacketsPerDr) { // not required
		return nil
	}

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) validateRxPacketsPerFreq(formats strfmt.Registry) error {
	if swag.IsZero(m.RxPacketsPerFreq) { // not required
		return nil
	}

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

	return nil
}

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

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

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

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

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

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

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

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

func (m *APIGetDeviceLinkMetricsResponse) contextValidateErrors(ctx context.Context, formats strfmt.Registry) error {

	if m.Errors != nil {

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

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) contextValidateGwRssi(ctx context.Context, formats strfmt.Registry) error {

	if m.GwRssi != nil {

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

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) contextValidateGwSnr(ctx context.Context, formats strfmt.Registry) error {

	if m.GwSnr != nil {

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

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) contextValidateRxPackets(ctx context.Context, formats strfmt.Registry) error {

	if m.RxPackets != nil {

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

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) contextValidateRxPacketsPerDr(ctx context.Context, formats strfmt.Registry) error {

	if m.RxPacketsPerDr != nil {

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

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

	return nil
}

func (m *APIGetDeviceLinkMetricsResponse) contextValidateRxPacketsPerFreq(ctx context.Context, formats strfmt.Registry) error {

	if m.RxPacketsPerFreq != nil {

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

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

	return nil
}

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

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