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

// GetEcuStatsVinDbcReader is a Reader for the GetEcuStatsVinDbc structure.
type GetEcuStatsVinDbcReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *GetEcuStatsVinDbcReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewGetEcuStatsVinDbcOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewGetEcuStatsVinDbcBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewGetEcuStatsVinDbcUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewGetEcuStatsVinDbcServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[GET /ecu_stats/{vin}/{dbc}] GetEcuStatsVinDbc", response, response.Code())
	}
}

// NewGetEcuStatsVinDbcOK creates a GetEcuStatsVinDbcOK with default headers values
func NewGetEcuStatsVinDbcOK() *GetEcuStatsVinDbcOK {
	return &GetEcuStatsVinDbcOK{}
}

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

OK
*/
type GetEcuStatsVinDbcOK struct {
	Payload *GetEcuStatsVinDbcOKBody
}

// IsSuccess returns true when this get ecu stats vin dbc o k response has a 2xx status code
func (o *GetEcuStatsVinDbcOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this get ecu stats vin dbc o k response has a 3xx status code
func (o *GetEcuStatsVinDbcOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get ecu stats vin dbc o k response has a 4xx status code
func (o *GetEcuStatsVinDbcOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this get ecu stats vin dbc o k response has a 5xx status code
func (o *GetEcuStatsVinDbcOK) IsServerError() bool {
	return false
}

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

// Code gets the status code for the get ecu stats vin dbc o k response
func (o *GetEcuStatsVinDbcOK) Code() int {
	return 200
}

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

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

func (o *GetEcuStatsVinDbcOK) GetPayload() *GetEcuStatsVinDbcOKBody {
	return o.Payload
}

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

	o.Payload = new(GetEcuStatsVinDbcOKBody)

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

	return nil
}

// NewGetEcuStatsVinDbcBadRequest creates a GetEcuStatsVinDbcBadRequest with default headers values
func NewGetEcuStatsVinDbcBadRequest() *GetEcuStatsVinDbcBadRequest {
	return &GetEcuStatsVinDbcBadRequest{}
}

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

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

// IsSuccess returns true when this get ecu stats vin dbc bad request response has a 2xx status code
func (o *GetEcuStatsVinDbcBadRequest) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get ecu stats vin dbc bad request response has a 3xx status code
func (o *GetEcuStatsVinDbcBadRequest) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get ecu stats vin dbc bad request response has a 4xx status code
func (o *GetEcuStatsVinDbcBadRequest) IsClientError() bool {
	return true
}

// IsServerError returns true when this get ecu stats vin dbc bad request response has a 5xx status code
func (o *GetEcuStatsVinDbcBadRequest) IsServerError() bool {
	return false
}

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

// Code gets the status code for the get ecu stats vin dbc bad request response
func (o *GetEcuStatsVinDbcBadRequest) Code() int {
	return 400
}

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

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

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

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

// NewGetEcuStatsVinDbcUnauthorized creates a GetEcuStatsVinDbcUnauthorized with default headers values
func NewGetEcuStatsVinDbcUnauthorized() *GetEcuStatsVinDbcUnauthorized {
	return &GetEcuStatsVinDbcUnauthorized{}
}

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

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

// IsSuccess returns true when this get ecu stats vin dbc unauthorized response has a 2xx status code
func (o *GetEcuStatsVinDbcUnauthorized) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get ecu stats vin dbc unauthorized response has a 3xx status code
func (o *GetEcuStatsVinDbcUnauthorized) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get ecu stats vin dbc unauthorized response has a 4xx status code
func (o *GetEcuStatsVinDbcUnauthorized) IsClientError() bool {
	return true
}

// IsServerError returns true when this get ecu stats vin dbc unauthorized response has a 5xx status code
func (o *GetEcuStatsVinDbcUnauthorized) IsServerError() bool {
	return false
}

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

// Code gets the status code for the get ecu stats vin dbc unauthorized response
func (o *GetEcuStatsVinDbcUnauthorized) Code() int {
	return 401
}

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

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

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

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

// NewGetEcuStatsVinDbcServiceUnavailable creates a GetEcuStatsVinDbcServiceUnavailable with default headers values
func NewGetEcuStatsVinDbcServiceUnavailable() *GetEcuStatsVinDbcServiceUnavailable {
	return &GetEcuStatsVinDbcServiceUnavailable{}
}

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

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

// IsSuccess returns true when this get ecu stats vin dbc service unavailable response has a 2xx status code
func (o *GetEcuStatsVinDbcServiceUnavailable) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get ecu stats vin dbc service unavailable response has a 3xx status code
func (o *GetEcuStatsVinDbcServiceUnavailable) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get ecu stats vin dbc service unavailable response has a 4xx status code
func (o *GetEcuStatsVinDbcServiceUnavailable) IsClientError() bool {
	return false
}

// IsServerError returns true when this get ecu stats vin dbc service unavailable response has a 5xx status code
func (o *GetEcuStatsVinDbcServiceUnavailable) IsServerError() bool {
	return true
}

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

// Code gets the status code for the get ecu stats vin dbc service unavailable response
func (o *GetEcuStatsVinDbcServiceUnavailable) Code() int {
	return 503
}

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

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

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

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

/*
GetEcuStatsVinDbcOKBody get ecu stats vin dbc o k body
swagger:model GetEcuStatsVinDbcOKBody
*/
type GetEcuStatsVinDbcOKBody struct {
	models.CommonJSONDBQueryResult

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

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

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

	o.Data = dataGetEcuStatsVinDbcOKBodyAO1.Data

	return nil
}

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

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

	dataGetEcuStatsVinDbcOKBodyAO1.Data = o.Data

	jsonDataGetEcuStatsVinDbcOKBodyAO1, errGetEcuStatsVinDbcOKBodyAO1 := swag.WriteJSON(dataGetEcuStatsVinDbcOKBodyAO1)
	if errGetEcuStatsVinDbcOKBodyAO1 != nil {
		return nil, errGetEcuStatsVinDbcOKBodyAO1
	}
	_parts = append(_parts, jsonDataGetEcuStatsVinDbcOKBodyAO1)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this get ecu stats vin dbc o k body
func (o *GetEcuStatsVinDbcOKBody) 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 *GetEcuStatsVinDbcOKBody) 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("getEcuStatsVinDbcOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getEcuStatsVinDbcOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

	}

	return nil
}

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

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