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

// GetCanSignalsListReader is a Reader for the GetCanSignalsList structure.
type GetCanSignalsListReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *GetCanSignalsListReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewGetCanSignalsListOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewGetCanSignalsListBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewGetCanSignalsListUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewGetCanSignalsListServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[GET /can_signals_list] GetCanSignalsList", response, response.Code())
	}
}

// NewGetCanSignalsListOK creates a GetCanSignalsListOK with default headers values
func NewGetCanSignalsListOK() *GetCanSignalsListOK {
	return &GetCanSignalsListOK{}
}

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

list of cars
*/
type GetCanSignalsListOK struct {
	Payload *GetCanSignalsListOKBody
}

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

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

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

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

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

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

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

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

func (o *GetCanSignalsListOK) GetPayload() *GetCanSignalsListOKBody {
	return o.Payload
}

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

	o.Payload = new(GetCanSignalsListOKBody)

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

	return nil
}

// NewGetCanSignalsListBadRequest creates a GetCanSignalsListBadRequest with default headers values
func NewGetCanSignalsListBadRequest() *GetCanSignalsListBadRequest {
	return &GetCanSignalsListBadRequest{}
}

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

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

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

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

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

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

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

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

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

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

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

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

// NewGetCanSignalsListUnauthorized creates a GetCanSignalsListUnauthorized with default headers values
func NewGetCanSignalsListUnauthorized() *GetCanSignalsListUnauthorized {
	return &GetCanSignalsListUnauthorized{}
}

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

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

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

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

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

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

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

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

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

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

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

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

// NewGetCanSignalsListServiceUnavailable creates a GetCanSignalsListServiceUnavailable with default headers values
func NewGetCanSignalsListServiceUnavailable() *GetCanSignalsListServiceUnavailable {
	return &GetCanSignalsListServiceUnavailable{}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	o.Data = dataGetCanSignalsListOKBodyAO1.Data

	return nil
}

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

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

	dataGetCanSignalsListOKBodyAO1.Data = o.Data

	jsonDataGetCanSignalsListOKBodyAO1, errGetCanSignalsListOKBodyAO1 := swag.WriteJSON(dataGetCanSignalsListOKBodyAO1)
	if errGetCanSignalsListOKBodyAO1 != nil {
		return nil, errGetCanSignalsListOKBodyAO1
	}
	_parts = append(_parts, jsonDataGetCanSignalsListOKBodyAO1)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this get can signals list o k body
func (o *GetCanSignalsListOKBody) 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 *GetCanSignalsListOKBody) 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("getCanSignalsListOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getCanSignalsListOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this get can signals list o k body based on the context it is used
func (o *GetCanSignalsListOKBody) 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 *GetCanSignalsListOKBody) 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("getCanSignalsListOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getCanSignalsListOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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