// Code generated by go-swagger; DO NOT EDIT.

package metadata

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"fmt"
	"io"
	"strconv"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
)

// ListMembershipsReader is a Reader for the ListMemberships structure.
type ListMembershipsReader struct {
	formats strfmt.Registry
}

// ReadResponse reads a server response into the received o.
func (o *ListMembershipsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
	switch response.Code() {
	case 200:
		result := NewListMembershipsOK()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return result, nil
	case 500:
		result := NewListMembershipsInternalServerError()
		if err := result.readResponse(response, consumer, o.formats); err != nil {
			return nil, err
		}
		return nil, result
	default:
		return nil, runtime.NewAPIError("[GET /memberships] listMemberships", response, response.Code())
	}
}

// NewListMembershipsOK creates a ListMembershipsOK with default headers values
func NewListMembershipsOK() *ListMembershipsOK {
	return &ListMembershipsOK{}
}

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

ok
*/
type ListMembershipsOK struct {
	Payload *ListMembershipsOKBody
}

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

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

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

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

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

// Code gets the status code for the list memberships o k response
func (o *ListMembershipsOK) Code() int {
	return 200
}

func (o *ListMembershipsOK) Error() string {
	return fmt.Sprintf("[GET /memberships][%d] listMembershipsOK  %+v", 200, o.Payload)
}

func (o *ListMembershipsOK) String() string {
	return fmt.Sprintf("[GET /memberships][%d] listMembershipsOK  %+v", 200, o.Payload)
}

func (o *ListMembershipsOK) GetPayload() *ListMembershipsOKBody {
	return o.Payload
}

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

	o.Payload = new(ListMembershipsOKBody)

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

	return nil
}

// NewListMembershipsInternalServerError creates a ListMembershipsInternalServerError with default headers values
func NewListMembershipsInternalServerError() *ListMembershipsInternalServerError {
	return &ListMembershipsInternalServerError{}
}

/*
ListMembershipsInternalServerError describes a response with status code 500, with default header values.

internal server error
*/
type ListMembershipsInternalServerError struct {
}

// IsSuccess returns true when this list memberships internal server error response has a 2xx status code
func (o *ListMembershipsInternalServerError) IsSuccess() bool {
	return false
}

// IsRedirect returns true when this list memberships internal server error response has a 3xx status code
func (o *ListMembershipsInternalServerError) IsRedirect() bool {
	return false
}

// IsClientError returns true when this list memberships internal server error response has a 4xx status code
func (o *ListMembershipsInternalServerError) IsClientError() bool {
	return false
}

// IsServerError returns true when this list memberships internal server error response has a 5xx status code
func (o *ListMembershipsInternalServerError) IsServerError() bool {
	return true
}

// IsCode returns true when this list memberships internal server error response a status code equal to that given
func (o *ListMembershipsInternalServerError) IsCode(code int) bool {
	return code == 500
}

// Code gets the status code for the list memberships internal server error response
func (o *ListMembershipsInternalServerError) Code() int {
	return 500
}

func (o *ListMembershipsInternalServerError) Error() string {
	return fmt.Sprintf("[GET /memberships][%d] listMembershipsInternalServerError ", 500)
}

func (o *ListMembershipsInternalServerError) String() string {
	return fmt.Sprintf("[GET /memberships][%d] listMembershipsInternalServerError ", 500)
}

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

	return nil
}

/*
ListMembershipsOKBody list memberships o k body
swagger:model ListMembershipsOKBody
*/
type ListMembershipsOKBody struct {

	// memberships
	Memberships []*ListMembershipsOKBodyMembershipsItems0 `json:"memberships"`
}

// Validate validates this list memberships o k body
func (o *ListMembershipsOKBody) Validate(formats strfmt.Registry) error {
	var res []error

	if err := o.validateMemberships(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (o *ListMembershipsOKBody) validateMemberships(formats strfmt.Registry) error {
	if swag.IsZero(o.Memberships) { // not required
		return nil
	}

	for i := 0; i < len(o.Memberships); i++ {
		if swag.IsZero(o.Memberships[i]) { // not required
			continue
		}

		if o.Memberships[i] != nil {
			if err := o.Memberships[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("listMembershipsOK" + "." + "memberships" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("listMembershipsOK" + "." + "memberships" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this list memberships o k body based on the context it is used
func (o *ListMembershipsOKBody) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	if err := o.contextValidateMemberships(ctx, formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

func (o *ListMembershipsOKBody) contextValidateMemberships(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(o.Memberships); i++ {

		if o.Memberships[i] != nil {

			if swag.IsZero(o.Memberships[i]) { // not required
				return nil
			}

			if err := o.Memberships[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("listMembershipsOK" + "." + "memberships" + "." + strconv.Itoa(i))
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("listMembershipsOK" + "." + "memberships" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

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

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

/*
ListMembershipsOKBodyMembershipsItems0 list memberships o k body memberships items0
swagger:model ListMembershipsOKBodyMembershipsItems0
*/
type ListMembershipsOKBodyMembershipsItems0 struct {

	// admin
	Admin bool `json:"admin,omitempty"`

	// description
	Description string `json:"description,omitempty"`

	// token
	Token string `json:"token,omitempty"`
}

// Validate validates this list memberships o k body memberships items0
func (o *ListMembershipsOKBodyMembershipsItems0) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this list memberships o k body memberships items0 based on context it is used
func (o *ListMembershipsOKBodyMembershipsItems0) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

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

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