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

// PostCarupdateReader is a Reader for the PostCarupdate structure.
type PostCarupdateReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *PostCarupdateReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewPostCarupdateOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewPostCarupdateBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewPostCarupdateUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewPostCarupdateServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[POST /carupdate] PostCarupdate", response, response.Code())
	}
}

// NewPostCarupdateOK creates a PostCarupdateOK with default headers values
func NewPostCarupdateOK() *PostCarupdateOK {
	return &PostCarupdateOK{}
}

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

Created car updates result
*/
type PostCarupdateOK struct {
	Payload *PostCarupdateOKBody
}

// IsSuccess returns true when this post carupdate o k response has a 2xx status code
func (o *PostCarupdateOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this post carupdate o k response has a 3xx status code
func (o *PostCarupdateOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this post carupdate o k response has a 4xx status code
func (o *PostCarupdateOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this post carupdate o k response has a 5xx status code
func (o *PostCarupdateOK) IsServerError() bool {
	return false
}

// IsCode returns true when this post carupdate o k response a status code equal to that given
func (o *PostCarupdateOK) IsCode(code int) bool {
	return code == 200
}

// Code gets the status code for the post carupdate o k response
func (o *PostCarupdateOK) Code() int {
	return 200
}

func (o *PostCarupdateOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateOK %s", 200, payload)
}

func (o *PostCarupdateOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateOK %s", 200, payload)
}

func (o *PostCarupdateOK) GetPayload() *PostCarupdateOKBody {
	return o.Payload
}

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

	o.Payload = new(PostCarupdateOKBody)

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

	return nil
}

// NewPostCarupdateBadRequest creates a PostCarupdateBadRequest with default headers values
func NewPostCarupdateBadRequest() *PostCarupdateBadRequest {
	return &PostCarupdateBadRequest{}
}

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

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

// IsSuccess returns true when this post carupdate bad request response has a 2xx status code
func (o *PostCarupdateBadRequest) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this post carupdate bad request response has a 3xx status code
func (o *PostCarupdateBadRequest) IsRedirect() bool {
	return false
}

// IsClientError returns true when this post carupdate bad request response has a 4xx status code
func (o *PostCarupdateBadRequest) IsClientError() bool {
	return true
}

// IsServerError returns true when this post carupdate bad request response has a 5xx status code
func (o *PostCarupdateBadRequest) IsServerError() bool {
	return false
}

// IsCode returns true when this post carupdate bad request response a status code equal to that given
func (o *PostCarupdateBadRequest) IsCode(code int) bool {
	return code == 400
}

// Code gets the status code for the post carupdate bad request response
func (o *PostCarupdateBadRequest) Code() int {
	return 400
}

func (o *PostCarupdateBadRequest) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateBadRequest %s", 400, payload)
}

func (o *PostCarupdateBadRequest) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateBadRequest %s", 400, payload)
}

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

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

// NewPostCarupdateUnauthorized creates a PostCarupdateUnauthorized with default headers values
func NewPostCarupdateUnauthorized() *PostCarupdateUnauthorized {
	return &PostCarupdateUnauthorized{}
}

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

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

// IsSuccess returns true when this post carupdate unauthorized response has a 2xx status code
func (o *PostCarupdateUnauthorized) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this post carupdate unauthorized response has a 3xx status code
func (o *PostCarupdateUnauthorized) IsRedirect() bool {
	return false
}

// IsClientError returns true when this post carupdate unauthorized response has a 4xx status code
func (o *PostCarupdateUnauthorized) IsClientError() bool {
	return true
}

// IsServerError returns true when this post carupdate unauthorized response has a 5xx status code
func (o *PostCarupdateUnauthorized) IsServerError() bool {
	return false
}

// IsCode returns true when this post carupdate unauthorized response a status code equal to that given
func (o *PostCarupdateUnauthorized) IsCode(code int) bool {
	return code == 401
}

// Code gets the status code for the post carupdate unauthorized response
func (o *PostCarupdateUnauthorized) Code() int {
	return 401
}

func (o *PostCarupdateUnauthorized) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateUnauthorized %s", 401, payload)
}

func (o *PostCarupdateUnauthorized) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateUnauthorized %s", 401, payload)
}

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

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

// NewPostCarupdateServiceUnavailable creates a PostCarupdateServiceUnavailable with default headers values
func NewPostCarupdateServiceUnavailable() *PostCarupdateServiceUnavailable {
	return &PostCarupdateServiceUnavailable{}
}

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

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

// IsSuccess returns true when this post carupdate service unavailable response has a 2xx status code
func (o *PostCarupdateServiceUnavailable) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this post carupdate service unavailable response has a 3xx status code
func (o *PostCarupdateServiceUnavailable) IsRedirect() bool {
	return false
}

// IsClientError returns true when this post carupdate service unavailable response has a 4xx status code
func (o *PostCarupdateServiceUnavailable) IsClientError() bool {
	return false
}

// IsServerError returns true when this post carupdate service unavailable response has a 5xx status code
func (o *PostCarupdateServiceUnavailable) IsServerError() bool {
	return true
}

// IsCode returns true when this post carupdate service unavailable response a status code equal to that given
func (o *PostCarupdateServiceUnavailable) IsCode(code int) bool {
	return code == 503
}

// Code gets the status code for the post carupdate service unavailable response
func (o *PostCarupdateServiceUnavailable) Code() int {
	return 503
}

func (o *PostCarupdateServiceUnavailable) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateServiceUnavailable %s", 503, payload)
}

func (o *PostCarupdateServiceUnavailable) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[POST /carupdate][%d] postCarupdateServiceUnavailable %s", 503, payload)
}

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

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

/*
PostCarupdateOKBody post carupdate o k body
swagger:model PostCarupdateOKBody
*/
type PostCarupdateOKBody struct {
	models.CommonJSONDBQueryResult

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

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

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

	o.Data = dataPostCarupdateOKBodyAO1.Data

	return nil
}

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

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

	dataPostCarupdateOKBodyAO1.Data = o.Data

	jsonDataPostCarupdateOKBodyAO1, errPostCarupdateOKBodyAO1 := swag.WriteJSON(dataPostCarupdateOKBodyAO1)
	if errPostCarupdateOKBodyAO1 != nil {
		return nil, errPostCarupdateOKBodyAO1
	}
	_parts = append(_parts, jsonDataPostCarupdateOKBodyAO1)
	return swag.ConcatJSON(_parts...), nil
}

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

	}

	return nil
}

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

	}

	return nil
}

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

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