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

package multicast_group_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"

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

// MulticastGroupServiceUpdateReader is a Reader for the MulticastGroupServiceUpdate structure.
type MulticastGroupServiceUpdateReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *MulticastGroupServiceUpdateReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewMulticastGroupServiceUpdateOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	default:
		result := NewMulticastGroupServiceUpdateDefault(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
	}
}

// NewMulticastGroupServiceUpdateOK creates a MulticastGroupServiceUpdateOK with default headers values
func NewMulticastGroupServiceUpdateOK() *MulticastGroupServiceUpdateOK {
	return &MulticastGroupServiceUpdateOK{}
}

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

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

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

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

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

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

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

// Code gets the status code for the multicast group service update o k response
func (o *MulticastGroupServiceUpdateOK) Code() int {
	return 200
}

func (o *MulticastGroupServiceUpdateOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/multicast-groups/{multicastGroup.id}][%d] multicastGroupServiceUpdateOK %s", 200, payload)
}

func (o *MulticastGroupServiceUpdateOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/multicast-groups/{multicastGroup.id}][%d] multicastGroupServiceUpdateOK %s", 200, payload)
}

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

func (o *MulticastGroupServiceUpdateOK) 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
}

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

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

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

	Payload *models.RPCStatus
}

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

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

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

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

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

// Code gets the status code for the multicast group service update default response
func (o *MulticastGroupServiceUpdateDefault) Code() int {
	return o._statusCode
}

func (o *MulticastGroupServiceUpdateDefault) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/multicast-groups/{multicastGroup.id}][%d] MulticastGroupService_Update default %s", o._statusCode, payload)
}

func (o *MulticastGroupServiceUpdateDefault) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/multicast-groups/{multicastGroup.id}][%d] MulticastGroupService_Update default %s", o._statusCode, payload)
}

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

func (o *MulticastGroupServiceUpdateDefault) 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
}

/*
MulticastGroupServiceUpdateBody multicast group service update body
swagger:model MulticastGroupServiceUpdateBody
*/
type MulticastGroupServiceUpdateBody struct {

	// multicast group
	MulticastGroup *MulticastGroupServiceUpdateParamsBodyMulticastGroup `json:"multicastGroup,omitempty"`
}

// Validate validates this multicast group service update body
func (o *MulticastGroupServiceUpdateBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (o *MulticastGroupServiceUpdateBody) validateMulticastGroup(formats strfmt.Registry) error {
	if swag.IsZero(o.MulticastGroup) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (o *MulticastGroupServiceUpdateBody) contextValidateMulticastGroup(ctx context.Context, formats strfmt.Registry) error {

	if o.MulticastGroup != nil {

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

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

	return nil
}

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

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

/*
MulticastGroupServiceUpdateParamsBodyMulticastGroup Multicast group object to update.
swagger:model MulticastGroupServiceUpdateParamsBodyMulticastGroup
*/
type MulticastGroupServiceUpdateParamsBodyMulticastGroup 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 *models.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 *models.APIMulticastGroupType `json:"groupType,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 *models.CommonRegion `json:"region,omitempty"`
}

// Validate validates this multicast group service update params body multicast group
func (o *MulticastGroupServiceUpdateParamsBodyMulticastGroup) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

	return nil
}

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

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

	return nil
}

func (o *MulticastGroupServiceUpdateParamsBodyMulticastGroup) 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" + "." + "multicastGroup" + "." + "region")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "multicastGroup" + "." + "region")
			}
			return err
		}
	}

	return nil
}

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

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

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

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

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

func (o *MulticastGroupServiceUpdateParamsBodyMulticastGroup) contextValidateClassCSchedulingType(ctx context.Context, formats strfmt.Registry) error {

	if o.ClassCSchedulingType != nil {

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

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

	return nil
}

func (o *MulticastGroupServiceUpdateParamsBodyMulticastGroup) contextValidateGroupType(ctx context.Context, formats strfmt.Registry) error {

	if o.GroupType != nil {

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

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

	return nil
}

func (o *MulticastGroupServiceUpdateParamsBodyMulticastGroup) 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" + "." + "multicastGroup" + "." + "region")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("body" + "." + "multicastGroup" + "." + "region")
			}
			return err
		}
	}

	return nil
}

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

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