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

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

// DeviceServiceCreateKeysReader is a Reader for the DeviceServiceCreateKeys structure.
type DeviceServiceCreateKeysReader struct {
	formats strfmt.Registry
}

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

// NewDeviceServiceCreateKeysOK creates a DeviceServiceCreateKeysOK with default headers values
func NewDeviceServiceCreateKeysOK() *DeviceServiceCreateKeysOK {
	return &DeviceServiceCreateKeysOK{}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	Payload *models.RPCStatus
}

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

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

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

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

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

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

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

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

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

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

/*
DeviceServiceCreateKeysBody device service create keys body
swagger:model DeviceServiceCreateKeysBody
*/
type DeviceServiceCreateKeysBody struct {

	// device keys
	DeviceKeys *DeviceServiceCreateKeysParamsBodyDeviceKeys `json:"deviceKeys,omitempty"`
}

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

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

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

func (o *DeviceServiceCreateKeysBody) validateDeviceKeys(formats strfmt.Registry) error {
	if swag.IsZero(o.DeviceKeys) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (o *DeviceServiceCreateKeysBody) contextValidateDeviceKeys(ctx context.Context, formats strfmt.Registry) error {

	if o.DeviceKeys != nil {

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

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

	return nil
}

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

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

/*
DeviceServiceCreateKeysParamsBodyDeviceKeys Device-keys object.
swagger:model DeviceServiceCreateKeysParamsBodyDeviceKeys
*/
type DeviceServiceCreateKeysParamsBodyDeviceKeys struct {

	// Application root key (128 bit).
	// Note: This field only needs to be set for LoRaWAN 1.1.x devices!
	AppKey string `json:"appKey,omitempty"`

	// Gen App Key (128 bit).
	// Note: This field only needs to be set for LoRaWAN 1.0.x devices that
	// implement TS005 (remote multicast setup).
	GenAppKey string `json:"genAppKey,omitempty"`

	// Network root key (128 bit).
	// Note: For LoRaWAN 1.0.x, use this field for the LoRaWAN 1.0.x 'AppKey`!
	NwkKey string `json:"nwkKey,omitempty"`
}

// Validate validates this device service create keys params body device keys
func (o *DeviceServiceCreateKeysParamsBodyDeviceKeys) Validate(formats strfmt.Registry) error {
	return nil
}

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

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

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