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

package models

import (
	"context"
	stderrors "errors"
	"strconv"

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

// ExamplepbRepeatedResponseBodyOut examplepb repeated response body out
//
// swagger:model examplepbRepeatedResponseBodyOut
type ExamplepbRepeatedResponseBodyOut struct {

	// response
	Response []*ExamplepbRepeatedResponseBodyOutResponse `json:"response"`
}

// Validate validates this examplepb repeated response body out
func (m *ExamplepbRepeatedResponseBodyOut) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *ExamplepbRepeatedResponseBodyOut) validateResponse(formats strfmt.Registry) error {
	if swag.IsZero(m.Response) { // not required
		return nil
	}

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

		if m.Response[i] != nil {
			if err := m.Response[i].Validate(formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("response" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("response" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this examplepb repeated response body out based on the context it is used
func (m *ExamplepbRepeatedResponseBodyOut) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *ExamplepbRepeatedResponseBodyOut) contextValidateResponse(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Response); i++ {

		if m.Response[i] != nil {

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

			if err := m.Response[i].ContextValidate(ctx, formats); err != nil {
				ve := new(errors.Validation)
				if stderrors.As(err, &ve) {
					return ve.ValidateName("response" + "." + strconv.Itoa(i))
				}
				ce := new(errors.CompositeError)
				if stderrors.As(err, &ce) {
					return ce.ValidateName("response" + "." + strconv.Itoa(i))
				}

				return err
			}
		}

	}

	return nil
}

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

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