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

// GetFleetsReader is a Reader for the GetFleets structure.
type GetFleetsReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *GetFleetsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewGetFleetsOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 400:
		result := NewGetFleetsBadRequest()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 401:
		result := NewGetFleetsUnauthorized()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	case 503:
		result := NewGetFleetsServiceUnavailable()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[GET /fleets] GetFleets", response, response.Code())
	}
}

// NewGetFleetsOK creates a GetFleetsOK with default headers values
func NewGetFleetsOK() *GetFleetsOK {
	return &GetFleetsOK{}
}

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

OK
*/
type GetFleetsOK struct {
	Payload *GetFleetsOKBody
}

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

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

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

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

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

// Code gets the status code for the get fleets o k response
func (o *GetFleetsOK) Code() int {
	return 200
}

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

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

func (o *GetFleetsOK) GetPayload() *GetFleetsOKBody {
	return o.Payload
}

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

	o.Payload = new(GetFleetsOKBody)

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

	return nil
}

// NewGetFleetsBadRequest creates a GetFleetsBadRequest with default headers values
func NewGetFleetsBadRequest() *GetFleetsBadRequest {
	return &GetFleetsBadRequest{}
}

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

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

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

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

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

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

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

// Code gets the status code for the get fleets bad request response
func (o *GetFleetsBadRequest) Code() int {
	return 400
}

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

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

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

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

// NewGetFleetsUnauthorized creates a GetFleetsUnauthorized with default headers values
func NewGetFleetsUnauthorized() *GetFleetsUnauthorized {
	return &GetFleetsUnauthorized{}
}

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

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

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

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

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

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

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

// Code gets the status code for the get fleets unauthorized response
func (o *GetFleetsUnauthorized) Code() int {
	return 401
}

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

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

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

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

// NewGetFleetsServiceUnavailable creates a GetFleetsServiceUnavailable with default headers values
func NewGetFleetsServiceUnavailable() *GetFleetsServiceUnavailable {
	return &GetFleetsServiceUnavailable{}
}

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

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

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

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

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

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

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

// Code gets the status code for the get fleets service unavailable response
func (o *GetFleetsServiceUnavailable) Code() int {
	return 503
}

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

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

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

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

/*
GetFleetsOKBody get fleets o k body
swagger:model GetFleetsOKBody
*/
type GetFleetsOKBody struct {
	models.CommonJSONDBQueryResult

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

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

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

	o.Data = dataGetFleetsOKBodyAO1.Data

	return nil
}

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

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

	dataGetFleetsOKBodyAO1.Data = o.Data

	jsonDataGetFleetsOKBodyAO1, errGetFleetsOKBodyAO1 := swag.WriteJSON(dataGetFleetsOKBodyAO1)
	if errGetFleetsOKBodyAO1 != nil {
		return nil, errGetFleetsOKBodyAO1
	}
	_parts = append(_parts, jsonDataGetFleetsOKBodyAO1)
	return swag.ConcatJSON(_parts...), nil
}

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

	}

	return nil
}

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

	}

	return nil
}

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

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