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

package models

import (
	"context"
	stderrors "errors"

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

// ProtoExamplepbFoo proto examplepb foo
//
// swagger:model protoExamplepbFoo
type ProtoExamplepbFoo struct {

	// bar
	// Required: true
	Bar *ExamplepbBar `json:"bar"`
}

// Validate validates this proto examplepb foo
func (m *ProtoExamplepbFoo) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *ProtoExamplepbFoo) validateBar(formats strfmt.Registry) error {

	if err := validate.Required("bar", "body", m.Bar); err != nil {
		return err
	}

	if m.Bar != nil {
		if err := m.Bar.Validate(formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("bar")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("bar")
			}

			return err
		}
	}

	return nil
}

// ContextValidate validate this proto examplepb foo based on the context it is used
func (m *ProtoExamplepbFoo) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *ProtoExamplepbFoo) contextValidateBar(ctx context.Context, formats strfmt.Registry) error {

	if m.Bar != nil {

		if err := m.Bar.ContextValidate(ctx, formats); err != nil {
			ve := new(errors.Validation)
			if stderrors.As(err, &ve) {
				return ve.ValidateName("bar")
			}
			ce := new(errors.CompositeError)
			if stderrors.As(err, &ce) {
				return ce.ValidateName("bar")
			}

			return err
		}
	}

	return nil
}

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

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