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

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

// DeviceServiceEnqueueReader is a Reader for the DeviceServiceEnqueue structure.
type DeviceServiceEnqueueReader struct {
	formats strfmt.Registry
}

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

// NewDeviceServiceEnqueueOK creates a DeviceServiceEnqueueOK with default headers values
func NewDeviceServiceEnqueueOK() *DeviceServiceEnqueueOK {
	return &DeviceServiceEnqueueOK{}
}

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

A successful response.
*/
type DeviceServiceEnqueueOK struct {
	Payload *models.APIEnqueueDeviceQueueItemResponse
}

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

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

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

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

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

// Code gets the status code for the device service enqueue o k response
func (o *DeviceServiceEnqueueOK) Code() int {
	return 200
}

func (o *DeviceServiceEnqueueOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /api/devices/{queueItem.devEui}/queue][%d] deviceServiceEnqueueOK %s", 200, payload)
}

func (o *DeviceServiceEnqueueOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /api/devices/{queueItem.devEui}/queue][%d] deviceServiceEnqueueOK %s", 200, payload)
}

func (o *DeviceServiceEnqueueOK) GetPayload() *models.APIEnqueueDeviceQueueItemResponse {
	return o.Payload
}

func (o *DeviceServiceEnqueueOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {

	o.Payload = new(models.APIEnqueueDeviceQueueItemResponse)

	// response payload
	if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
		return err
	}

	return nil
}

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

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

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

	Payload *models.RPCStatus
}

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

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

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

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

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

// Code gets the status code for the device service enqueue default response
func (o *DeviceServiceEnqueueDefault) Code() int {
	return o._statusCode
}

func (o *DeviceServiceEnqueueDefault) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /api/devices/{queueItem.devEui}/queue][%d] DeviceService_Enqueue default %s", o._statusCode, payload)
}

func (o *DeviceServiceEnqueueDefault) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /api/devices/{queueItem.devEui}/queue][%d] DeviceService_Enqueue default %s", o._statusCode, payload)
}

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

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

/*
DeviceServiceEnqueueBody device service enqueue body
swagger:model DeviceServiceEnqueueBody
*/
type DeviceServiceEnqueueBody struct {

	// queue item
	QueueItem *DeviceServiceEnqueueParamsBodyQueueItem `json:"queueItem,omitempty"`
}

// Validate validates this device service enqueue body
func (o *DeviceServiceEnqueueBody) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (o *DeviceServiceEnqueueBody) validateQueueItem(formats strfmt.Registry) error {
	if swag.IsZero(o.QueueItem) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (o *DeviceServiceEnqueueBody) contextValidateQueueItem(ctx context.Context, formats strfmt.Registry) error {

	if o.QueueItem != nil {

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

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

	return nil
}

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

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

/*
DeviceServiceEnqueueParamsBodyQueueItem device service enqueue params body queue item
swagger:model DeviceServiceEnqueueParamsBodyQueueItem
*/
type DeviceServiceEnqueueParamsBodyQueueItem struct {

	// Confirmed.
	Confirmed bool `json:"confirmed,omitempty"`

	// Data.
	// Or use the json_object field when a codec has been configured.
	// Format: byte
	Data strfmt.Base64 `json:"data,omitempty"`

	// Expires at (optional).
	// Expired queue-items will be automatically removed from the queue.
	// Format: date-time
	ExpiresAt strfmt.DateTime `json:"expiresAt,omitempty"`

	// Downlink frame-counter.
	// Do not set this for plain-text data payloads. It will be automatically set
	// by ChirpStack when the payload has been sent as downlink.
	FCntDown int64 `json:"fCntDown,omitempty"`

	// FPort (must be > 0).
	// On enqueue and if using a JavaScript codec, this value might be
	// automatically set by the codec function.
	FPort int64 `json:"fPort,omitempty"`

	// ID (UUID).
	// This is automatically generated on enqueue.
	ID string `json:"id,omitempty"`

	// Is encrypted.
	// This must be set to true if the end-application has already encrypted
	// the data payload. In this case, the f_cnt_down field must be set to
	// the corresponding frame-counter which has been used during the encryption.
	IsEncrypted bool `json:"isEncrypted,omitempty"`

	// Is pending.
	// This is set by ChirpStack to true when the downlink is pending (e.g. it
	// has been sent, but a confirmation is still pending).
	IsPending bool `json:"isPending,omitempty"`

	// Only use this when a codec has been configured that can encode this
	// object to bytes.
	Object interface{} `json:"object,omitempty"`
}

// Validate validates this device service enqueue params body queue item
func (o *DeviceServiceEnqueueParamsBodyQueueItem) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (o *DeviceServiceEnqueueParamsBodyQueueItem) validateExpiresAt(formats strfmt.Registry) error {
	if swag.IsZero(o.ExpiresAt) { // not required
		return nil
	}

	if err := validate.FormatOf("body"+"."+"queueItem"+"."+"expiresAt", "body", "date-time", o.ExpiresAt.String(), formats); err != nil {
		return err
	}

	return nil
}

// ContextValidate validates this device service enqueue params body queue item based on context it is used
func (o *DeviceServiceEnqueueParamsBodyQueueItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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