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

package device_profile_template_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"
)

// DeviceProfileTemplateServiceUpdateReader is a Reader for the DeviceProfileTemplateServiceUpdate structure.
type DeviceProfileTemplateServiceUpdateReader struct {
	formats strfmt.Registry
}

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

// NewDeviceProfileTemplateServiceUpdateOK creates a DeviceProfileTemplateServiceUpdateOK with default headers values
func NewDeviceProfileTemplateServiceUpdateOK() *DeviceProfileTemplateServiceUpdateOK {
	return &DeviceProfileTemplateServiceUpdateOK{}
}

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

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

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

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

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

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

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

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

func (o *DeviceProfileTemplateServiceUpdateOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profile-templates/{deviceProfileTemplate.id}][%d] deviceProfileTemplateServiceUpdateOK %s", 200, payload)
}

func (o *DeviceProfileTemplateServiceUpdateOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profile-templates/{deviceProfileTemplate.id}][%d] deviceProfileTemplateServiceUpdateOK %s", 200, payload)
}

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

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

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

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

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

	Payload *models.RPCStatus
}

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

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

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

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

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

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

func (o *DeviceProfileTemplateServiceUpdateDefault) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profile-templates/{deviceProfileTemplate.id}][%d] DeviceProfileTemplateService_Update default %s", o._statusCode, payload)
}

func (o *DeviceProfileTemplateServiceUpdateDefault) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[PUT /api/device-profile-templates/{deviceProfileTemplate.id}][%d] DeviceProfileTemplateService_Update default %s", o._statusCode, payload)
}

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

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

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

	// device profile template
	DeviceProfileTemplate *DeviceProfileTemplateServiceUpdateParamsBodyDeviceProfileTemplate `json:"deviceProfileTemplate,omitempty"`
}

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

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

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

func (o *DeviceProfileTemplateServiceUpdateBody) validateDeviceProfileTemplate(formats strfmt.Registry) error {
	if swag.IsZero(o.DeviceProfileTemplate) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (o *DeviceProfileTemplateServiceUpdateBody) contextValidateDeviceProfileTemplate(ctx context.Context, formats strfmt.Registry) error {

	if o.DeviceProfileTemplate != nil {

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

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

	return nil
}

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

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

/*
DeviceProfileTemplateServiceUpdateParamsBodyDeviceProfileTemplate Object to update.
swagger:model DeviceProfileTemplateServiceUpdateParamsBodyDeviceProfileTemplate
*/
type DeviceProfileTemplateServiceUpdateParamsBodyDeviceProfileTemplate 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"`

	// 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 (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"`

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

	// Firmware.
	Firmware string `json:"firmware,omitempty"`

	// Flush queue on device activation.
	FlushQueueOnActivate bool `json:"flushQueueOnActivate,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"`

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

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

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

	// User defined tags.
	Tags map[string]string `json:"tags,omitempty"`

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

	// Vendor.
	Vendor string `json:"vendor,omitempty"`
}

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

	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 len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

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

	return nil
}

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

	for k := range o.Measurements {

		if err := validate.Required("body"+"."+"deviceProfileTemplate"+"."+"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" + "." + "deviceProfileTemplate" + "." + "measurements" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("body" + "." + "deviceProfileTemplate" + "." + "measurements" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

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

	return nil
}

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

	return nil
}

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

	return nil
}

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

	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 len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

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

	return nil
}

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

	return nil
}

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

	return nil
}

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

	return nil
}

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

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