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

// APIMulticastGroup api multicast group
//
// swagger:model apiMulticastGroup
type APIMulticastGroup struct {

	// Application ID.
	// After creation, this can not be updated.
	ApplicationID string `json:"applicationId,omitempty"`

	// Class-B ping-slot periodicity (only for Class-B).
	// 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"`

	// Scheduling type (only for Class-C).
	ClassCSchedulingType *APIMulticastGroupSchedulingType `json:"classCSchedulingType,omitempty"`

	// Data-rate.
	Dr int64 `json:"dr,omitempty"`

	// Frame-counter.
	FCnt int64 `json:"fCnt,omitempty"`

	// Frequency (Hz).
	Frequency int64 `json:"frequency,omitempty"`

	// Multicast group type.
	GroupType *APIMulticastGroupType `json:"groupType,omitempty"`

	// ID (UUID).
	// This will be generated automatically on create.
	ID string `json:"id,omitempty"`

	// Multicast address (HEX encoded DevAddr).
	McAddr string `json:"mcAddr,omitempty"`

	// Multicast application session key (HEX encoded AES128 key).
	McAppSKey string `json:"mcAppSKey,omitempty"`

	// Multicast network session key (HEX encoded AES128 key).
	McNwkSKey string `json:"mcNwkSKey,omitempty"`

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

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

// Validate validates this api multicast group
func (m *APIMulticastGroup) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *APIMulticastGroup) validateClassCSchedulingType(formats strfmt.Registry) error {
	if swag.IsZero(m.ClassCSchedulingType) { // not required
		return nil
	}

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

	return nil
}

func (m *APIMulticastGroup) validateGroupType(formats strfmt.Registry) error {
	if swag.IsZero(m.GroupType) { // not required
		return nil
	}

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

	return nil
}

func (m *APIMulticastGroup) 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
}

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

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

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

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

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

func (m *APIMulticastGroup) contextValidateClassCSchedulingType(ctx context.Context, formats strfmt.Registry) error {

	if m.ClassCSchedulingType != nil {

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

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

	return nil
}

func (m *APIMulticastGroup) contextValidateGroupType(ctx context.Context, formats strfmt.Registry) error {

	if m.GroupType != nil {

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

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

	return nil
}

func (m *APIMulticastGroup) 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
}

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

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