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

// GetVehicleVinTrexLogsReader is a Reader for the GetVehicleVinTrexLogs structure.
type GetVehicleVinTrexLogsReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *GetVehicleVinTrexLogsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewGetVehicleVinTrexLogsOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewGetVehicleVinTrexLogsBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewGetVehicleVinTrexLogsUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 404:
		result := NewGetVehicleVinTrexLogsNotFound()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewGetVehicleVinTrexLogsServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[GET /vehicle/{vin}/trex-logs] GetVehicleVinTrexLogs", response, response.Code())
	}
}

// NewGetVehicleVinTrexLogsOK creates a GetVehicleVinTrexLogsOK with default headers values
func NewGetVehicleVinTrexLogsOK() *GetVehicleVinTrexLogsOK {
	return &GetVehicleVinTrexLogsOK{}
}

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

OK
*/
type GetVehicleVinTrexLogsOK struct {
	Payload *GetVehicleVinTrexLogsOKBody
}

// IsSuccess returns true when this get vehicle vin trex logs o k response has a 2xx status code
func (o *GetVehicleVinTrexLogsOK) IsSuccess() bool {
	return true
}

// IsRedirect returns true when this get vehicle vin trex logs o k response has a 3xx status code
func (o *GetVehicleVinTrexLogsOK) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get vehicle vin trex logs o k response has a 4xx status code
func (o *GetVehicleVinTrexLogsOK) IsClientError() bool {
	return false
}

// IsServerError returns true when this get vehicle vin trex logs o k response has a 5xx status code
func (o *GetVehicleVinTrexLogsOK) IsServerError() bool {
	return false
}

// IsCode returns true when this get vehicle vin trex logs o k response a status code equal to that given
func (o *GetVehicleVinTrexLogsOK) IsCode(code int) bool {
	return code == 200
}

// Code gets the status code for the get vehicle vin trex logs o k response
func (o *GetVehicleVinTrexLogsOK) Code() int {
	return 200
}

func (o *GetVehicleVinTrexLogsOK) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsOK %s", 200, payload)
}

func (o *GetVehicleVinTrexLogsOK) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsOK %s", 200, payload)
}

func (o *GetVehicleVinTrexLogsOK) GetPayload() *GetVehicleVinTrexLogsOKBody {
	return o.Payload
}

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

	o.Payload = new(GetVehicleVinTrexLogsOKBody)

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

	return nil
}

// NewGetVehicleVinTrexLogsBadRequest creates a GetVehicleVinTrexLogsBadRequest with default headers values
func NewGetVehicleVinTrexLogsBadRequest() *GetVehicleVinTrexLogsBadRequest {
	return &GetVehicleVinTrexLogsBadRequest{}
}

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

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

// IsSuccess returns true when this get vehicle vin trex logs bad request response has a 2xx status code
func (o *GetVehicleVinTrexLogsBadRequest) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get vehicle vin trex logs bad request response has a 3xx status code
func (o *GetVehicleVinTrexLogsBadRequest) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get vehicle vin trex logs bad request response has a 4xx status code
func (o *GetVehicleVinTrexLogsBadRequest) IsClientError() bool {
	return true
}

// IsServerError returns true when this get vehicle vin trex logs bad request response has a 5xx status code
func (o *GetVehicleVinTrexLogsBadRequest) IsServerError() bool {
	return false
}

// IsCode returns true when this get vehicle vin trex logs bad request response a status code equal to that given
func (o *GetVehicleVinTrexLogsBadRequest) IsCode(code int) bool {
	return code == 400
}

// Code gets the status code for the get vehicle vin trex logs bad request response
func (o *GetVehicleVinTrexLogsBadRequest) Code() int {
	return 400
}

func (o *GetVehicleVinTrexLogsBadRequest) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsBadRequest %s", 400, payload)
}

func (o *GetVehicleVinTrexLogsBadRequest) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsBadRequest %s", 400, payload)
}

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

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

// NewGetVehicleVinTrexLogsUnauthorized creates a GetVehicleVinTrexLogsUnauthorized with default headers values
func NewGetVehicleVinTrexLogsUnauthorized() *GetVehicleVinTrexLogsUnauthorized {
	return &GetVehicleVinTrexLogsUnauthorized{}
}

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

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

// IsSuccess returns true when this get vehicle vin trex logs unauthorized response has a 2xx status code
func (o *GetVehicleVinTrexLogsUnauthorized) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get vehicle vin trex logs unauthorized response has a 3xx status code
func (o *GetVehicleVinTrexLogsUnauthorized) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get vehicle vin trex logs unauthorized response has a 4xx status code
func (o *GetVehicleVinTrexLogsUnauthorized) IsClientError() bool {
	return true
}

// IsServerError returns true when this get vehicle vin trex logs unauthorized response has a 5xx status code
func (o *GetVehicleVinTrexLogsUnauthorized) IsServerError() bool {
	return false
}

// IsCode returns true when this get vehicle vin trex logs unauthorized response a status code equal to that given
func (o *GetVehicleVinTrexLogsUnauthorized) IsCode(code int) bool {
	return code == 401
}

// Code gets the status code for the get vehicle vin trex logs unauthorized response
func (o *GetVehicleVinTrexLogsUnauthorized) Code() int {
	return 401
}

func (o *GetVehicleVinTrexLogsUnauthorized) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsUnauthorized %s", 401, payload)
}

func (o *GetVehicleVinTrexLogsUnauthorized) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsUnauthorized %s", 401, payload)
}

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

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

// NewGetVehicleVinTrexLogsNotFound creates a GetVehicleVinTrexLogsNotFound with default headers values
func NewGetVehicleVinTrexLogsNotFound() *GetVehicleVinTrexLogsNotFound {
	return &GetVehicleVinTrexLogsNotFound{}
}

/*
GetVehicleVinTrexLogsNotFound describes a response with status code 404, with default header values.

Status not found
*/
type GetVehicleVinTrexLogsNotFound struct {
	Payload *models.CommonJSONError
}

// IsSuccess returns true when this get vehicle vin trex logs not found response has a 2xx status code
func (o *GetVehicleVinTrexLogsNotFound) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get vehicle vin trex logs not found response has a 3xx status code
func (o *GetVehicleVinTrexLogsNotFound) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get vehicle vin trex logs not found response has a 4xx status code
func (o *GetVehicleVinTrexLogsNotFound) IsClientError() bool {
	return true
}

// IsServerError returns true when this get vehicle vin trex logs not found response has a 5xx status code
func (o *GetVehicleVinTrexLogsNotFound) IsServerError() bool {
	return false
}

// IsCode returns true when this get vehicle vin trex logs not found response a status code equal to that given
func (o *GetVehicleVinTrexLogsNotFound) IsCode(code int) bool {
	return code == 404
}

// Code gets the status code for the get vehicle vin trex logs not found response
func (o *GetVehicleVinTrexLogsNotFound) Code() int {
	return 404
}

func (o *GetVehicleVinTrexLogsNotFound) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsNotFound %s", 404, payload)
}

func (o *GetVehicleVinTrexLogsNotFound) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsNotFound %s", 404, payload)
}

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

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

// NewGetVehicleVinTrexLogsServiceUnavailable creates a GetVehicleVinTrexLogsServiceUnavailable with default headers values
func NewGetVehicleVinTrexLogsServiceUnavailable() *GetVehicleVinTrexLogsServiceUnavailable {
	return &GetVehicleVinTrexLogsServiceUnavailable{}
}

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

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

// IsSuccess returns true when this get vehicle vin trex logs service unavailable response has a 2xx status code
func (o *GetVehicleVinTrexLogsServiceUnavailable) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this get vehicle vin trex logs service unavailable response has a 3xx status code
func (o *GetVehicleVinTrexLogsServiceUnavailable) IsRedirect() bool {
	return false
}

// IsClientError returns true when this get vehicle vin trex logs service unavailable response has a 4xx status code
func (o *GetVehicleVinTrexLogsServiceUnavailable) IsClientError() bool {
	return false
}

// IsServerError returns true when this get vehicle vin trex logs service unavailable response has a 5xx status code
func (o *GetVehicleVinTrexLogsServiceUnavailable) IsServerError() bool {
	return true
}

// IsCode returns true when this get vehicle vin trex logs service unavailable response a status code equal to that given
func (o *GetVehicleVinTrexLogsServiceUnavailable) IsCode(code int) bool {
	return code == 503
}

// Code gets the status code for the get vehicle vin trex logs service unavailable response
func (o *GetVehicleVinTrexLogsServiceUnavailable) Code() int {
	return 503
}

func (o *GetVehicleVinTrexLogsServiceUnavailable) Error() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsServiceUnavailable %s", 503, payload)
}

func (o *GetVehicleVinTrexLogsServiceUnavailable) String() string {
	payload, _ := json.Marshal(o.Payload)
	return fmt.Sprintf("[GET /vehicle/{vin}/trex-logs][%d] getVehicleVinTrexLogsServiceUnavailable %s", 503, payload)
}

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

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

/*
GetVehicleVinTrexLogsOKBody get vehicle vin trex logs o k body
swagger:model GetVehicleVinTrexLogsOKBody
*/
type GetVehicleVinTrexLogsOKBody struct {
	models.CommonJSONBlobReadResult

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

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

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

	o.Data = dataGetVehicleVinTrexLogsOKBodyAO1.Data

	return nil
}

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

	getVehicleVinTrexLogsOKBodyAO0, err := swag.WriteJSON(o.CommonJSONBlobReadResult)
	if err != nil {
		return nil, err
	}
	_parts = append(_parts, getVehicleVinTrexLogsOKBodyAO0)
	var dataGetVehicleVinTrexLogsOKBodyAO1 struct {
		Data []*models.CommonLogTrexLog `json:"data"`
	}

	dataGetVehicleVinTrexLogsOKBodyAO1.Data = o.Data

	jsonDataGetVehicleVinTrexLogsOKBodyAO1, errGetVehicleVinTrexLogsOKBodyAO1 := swag.WriteJSON(dataGetVehicleVinTrexLogsOKBodyAO1)
	if errGetVehicleVinTrexLogsOKBodyAO1 != nil {
		return nil, errGetVehicleVinTrexLogsOKBodyAO1
	}
	_parts = append(_parts, jsonDataGetVehicleVinTrexLogsOKBodyAO1)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this get vehicle vin trex logs o k body
func (o *GetVehicleVinTrexLogsOKBody) Validate(formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with models.CommonJSONBlobReadResult
	if err := o.CommonJSONBlobReadResult.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 *GetVehicleVinTrexLogsOKBody) 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("getVehicleVinTrexLogsOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getVehicleVinTrexLogsOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this get vehicle vin trex logs o k body based on the context it is used
func (o *GetVehicleVinTrexLogsOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with models.CommonJSONBlobReadResult
	if err := o.CommonJSONBlobReadResult.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 *GetVehicleVinTrexLogsOKBody) 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("getVehicleVinTrexLogsOK" + "." + "data" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("getVehicleVinTrexLogsOK" + "." + "data" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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