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

package operations

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

	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"

	"github.com/fiskerinc/cloud-services/pkg/ota_api/models"
)

// GetCanSignalsDbcReader is a Reader for the GetCanSignalsDbc structure.
type GetCanSignalsDbcReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *GetCanSignalsDbcReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewGetCanSignalsDbcOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewGetCanSignalsDbcBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewGetCanSignalsDbcUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewGetCanSignalsDbcServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[GET /can_signals/{dbc}] GetCanSignalsDbc", response, response.Code())
	}
}

// NewGetCanSignalsDbcOK creates a GetCanSignalsDbcOK with default headers values
func NewGetCanSignalsDbcOK() *GetCanSignalsDbcOK {
	return &GetCanSignalsDbcOK{}
}

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

OK
*/
type GetCanSignalsDbcOK struct {
	Payload *GetCanSignalsDbcOKBody
}

// IsSuccess returns true when this get can signals dbc o k response has a 2xx status code
func (o *GetCanSignalsDbcOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this get can signals dbc o k response has a 3xx status code
func (o *GetCanSignalsDbcOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get can signals dbc o k response has a 4xx status code
func (o *GetCanSignalsDbcOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this get can signals dbc o k response has a 5xx status code
func (o *GetCanSignalsDbcOK) IsServerError() bool {
	return false
}

// IsCode returns true when this get can signals dbc o k response a status code equal to that given
func (o *GetCanSignalsDbcOK) IsCode(code int) bool {
	return code == 200
}

// Code gets the status code for the get can signals dbc o k response
func (o *GetCanSignalsDbcOK) Code() int {
	return 200
}

func (o *GetCanSignalsDbcOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcOK %s", 200, payload)
}

func (o *GetCanSignalsDbcOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcOK %s", 200, payload)
}

func (o *GetCanSignalsDbcOK) GetPayload() *GetCanSignalsDbcOKBody {
	return o.Payload
}

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

	o.Payload = new(GetCanSignalsDbcOKBody)

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

	return nil
}

// NewGetCanSignalsDbcBadRequest creates a GetCanSignalsDbcBadRequest with default headers values
func NewGetCanSignalsDbcBadRequest() *GetCanSignalsDbcBadRequest {
	return &GetCanSignalsDbcBadRequest{}
}

/*
GetCanSignalsDbcBadRequest describes a response with status code 400, with default header values.

Bad request
*/
type GetCanSignalsDbcBadRequest struct {
	Payload *models.CommonJSONError
}

// IsSuccess returns true when this get can signals dbc bad request response has a 2xx status code
func (o *GetCanSignalsDbcBadRequest) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get can signals dbc bad request response has a 3xx status code
func (o *GetCanSignalsDbcBadRequest) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get can signals dbc bad request response has a 4xx status code
func (o *GetCanSignalsDbcBadRequest) IsClientError() bool {
	return true
}

// IsServerError returns true when this get can signals dbc bad request response has a 5xx status code
func (o *GetCanSignalsDbcBadRequest) IsServerError() bool {
	return false
}

// IsCode returns true when this get can signals dbc bad request response a status code equal to that given
func (o *GetCanSignalsDbcBadRequest) IsCode(code int) bool {
	return code == 400
}

// Code gets the status code for the get can signals dbc bad request response
func (o *GetCanSignalsDbcBadRequest) Code() int {
	return 400
}

func (o *GetCanSignalsDbcBadRequest) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcBadRequest %s", 400, payload)
}

func (o *GetCanSignalsDbcBadRequest) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcBadRequest %s", 400, payload)
}

func (o *GetCanSignalsDbcBadRequest) GetPayload() *models.CommonJSONError {
	return o.Payload
}

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

	o.Payload = new(models.CommonJSONError)

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

	return nil
}

// NewGetCanSignalsDbcUnauthorized creates a GetCanSignalsDbcUnauthorized with default headers values
func NewGetCanSignalsDbcUnauthorized() *GetCanSignalsDbcUnauthorized {
	return &GetCanSignalsDbcUnauthorized{}
}

/*
GetCanSignalsDbcUnauthorized describes a response with status code 401, with default header values.

Unauthorized
*/
type GetCanSignalsDbcUnauthorized struct {
	Payload *models.CommonJSONError
}

// IsSuccess returns true when this get can signals dbc unauthorized response has a 2xx status code
func (o *GetCanSignalsDbcUnauthorized) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get can signals dbc unauthorized response has a 3xx status code
func (o *GetCanSignalsDbcUnauthorized) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get can signals dbc unauthorized response has a 4xx status code
func (o *GetCanSignalsDbcUnauthorized) IsClientError() bool {
	return true
}

// IsServerError returns true when this get can signals dbc unauthorized response has a 5xx status code
func (o *GetCanSignalsDbcUnauthorized) IsServerError() bool {
	return false
}

// IsCode returns true when this get can signals dbc unauthorized response a status code equal to that given
func (o *GetCanSignalsDbcUnauthorized) IsCode(code int) bool {
	return code == 401
}

// Code gets the status code for the get can signals dbc unauthorized response
func (o *GetCanSignalsDbcUnauthorized) Code() int {
	return 401
}

func (o *GetCanSignalsDbcUnauthorized) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcUnauthorized %s", 401, payload)
}

func (o *GetCanSignalsDbcUnauthorized) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcUnauthorized %s", 401, payload)
}

func (o *GetCanSignalsDbcUnauthorized) GetPayload() *models.CommonJSONError {
	return o.Payload
}

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

	o.Payload = new(models.CommonJSONError)

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

	return nil
}

// NewGetCanSignalsDbcServiceUnavailable creates a GetCanSignalsDbcServiceUnavailable with default headers values
func NewGetCanSignalsDbcServiceUnavailable() *GetCanSignalsDbcServiceUnavailable {
	return &GetCanSignalsDbcServiceUnavailable{}
}

/*
GetCanSignalsDbcServiceUnavailable describes a response with status code 503, with default header values.

Service unavailable
*/
type GetCanSignalsDbcServiceUnavailable struct {
	Payload *models.CommonJSONError
}

// IsSuccess returns true when this get can signals dbc service unavailable response has a 2xx status code
func (o *GetCanSignalsDbcServiceUnavailable) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get can signals dbc service unavailable response has a 3xx status code
func (o *GetCanSignalsDbcServiceUnavailable) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get can signals dbc service unavailable response has a 4xx status code
func (o *GetCanSignalsDbcServiceUnavailable) IsClientError() bool {
	return false
}

// IsServerError returns true when this get can signals dbc service unavailable response has a 5xx status code
func (o *GetCanSignalsDbcServiceUnavailable) IsServerError() bool {
	return true
}

// IsCode returns true when this get can signals dbc service unavailable response a status code equal to that given
func (o *GetCanSignalsDbcServiceUnavailable) IsCode(code int) bool {
	return code == 503
}

// Code gets the status code for the get can signals dbc service unavailable response
func (o *GetCanSignalsDbcServiceUnavailable) Code() int {
	return 503
}

func (o *GetCanSignalsDbcServiceUnavailable) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcServiceUnavailable %s", 503, payload)
}

func (o *GetCanSignalsDbcServiceUnavailable) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /can_signals/{dbc}][%d] getCanSignalsDbcServiceUnavailable %s", 503, payload)
}

func (o *GetCanSignalsDbcServiceUnavailable) GetPayload() *models.CommonJSONError {
	return o.Payload
}

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

	o.Payload = new(models.CommonJSONError)

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

	return nil
}

/*
GetCanSignalsDbcOKBody get can signals dbc o k body
swagger:model GetCanSignalsDbcOKBody
*/
type GetCanSignalsDbcOKBody struct {
	models.CommonJSONDBQueryResult

	// data
	Data []*models.CommonSignalDescWithECU `json:"data"`
}

// UnmarshalJSON unmarshals this object from a JSON structure
func (o *GetCanSignalsDbcOKBody) UnmarshalJSON(raw []byte) error {
	// GetCanSignalsDbcOKBodyAO0
	var getCanSignalsDbcOKBodyAO0 models.CommonJSONDBQueryResult
	if err := swag.ReadJSON(raw, &getCanSignalsDbcOKBodyAO0); err != nil {
		return err
	}
	o.CommonJSONDBQueryResult = getCanSignalsDbcOKBodyAO0

	// GetCanSignalsDbcOKBodyAO1
	var dataGetCanSignalsDbcOKBodyAO1 struct {
		Data []*models.CommonSignalDescWithECU `json:"data"`
	}
	if err := swag.ReadJSON(raw, &dataGetCanSignalsDbcOKBodyAO1); err != nil {
		return err
	}

	o.Data = dataGetCanSignalsDbcOKBodyAO1.Data

	return nil
}

// MarshalJSON marshals this object to a JSON structure
func (o GetCanSignalsDbcOKBody) MarshalJSON() ([]byte, error) {
	_parts := make([][]byte, 0, 2)

	getCanSignalsDbcOKBodyAO0, err := swag.WriteJSON(o.CommonJSONDBQueryResult)
	if err != nil {
		return nil, err
	}
	_parts = append(_parts, getCanSignalsDbcOKBodyAO0)
	var dataGetCanSignalsDbcOKBodyAO1 struct {
		Data []*models.CommonSignalDescWithECU `json:"data"`
	}

	dataGetCanSignalsDbcOKBodyAO1.Data = o.Data

	jsonDataGetCanSignalsDbcOKBodyAO1, errGetCanSignalsDbcOKBodyAO1 := swag.WriteJSON(dataGetCanSignalsDbcOKBodyAO1)
	if errGetCanSignalsDbcOKBodyAO1 != nil {
		return nil, errGetCanSignalsDbcOKBodyAO1
	}
	_parts = append(_parts, jsonDataGetCanSignalsDbcOKBodyAO1)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this get can signals dbc o k body
func (o *GetCanSignalsDbcOKBody) Validate(formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with models.CommonJSONDBQueryResult
	if err := o.CommonJSONDBQueryResult.Validate(formats); err != nil {
		res = append(res, err)
	}

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

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

func (o *GetCanSignalsDbcOKBody) validateData(formats strfmt.Registry) error {

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

	for i := 0; i < len(o.Data); i++ {
		if swag.IsZero(o.Data[i]) { // not required
			continue
		}

		if o.Data[i] != nil {
			if err := o.Data[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("getCanSignalsDbcOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getCanSignalsDbcOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this get can signals dbc o k body based on the context it is used
func (o *GetCanSignalsDbcOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with models.CommonJSONDBQueryResult
	if err := o.CommonJSONDBQueryResult.ContextValidate(ctx, formats); err != nil {
		res = append(res, err)
	}

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

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

func (o *GetCanSignalsDbcOKBody) contextValidateData(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(o.Data); i++ {

		if o.Data[i] != nil {

			if swag.IsZero(o.Data[i]) { // not required
				return nil
			}

			if err := o.Data[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("getCanSignalsDbcOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getCanSignalsDbcOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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