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

// ExamplepbStatusCheckRequest StatusCheckRequest demonstrates name collision handling.
// It uses Status message from both sub and sub2 packages.
//
// swagger:model examplepbStatusCheckRequest
type ExamplepbStatusCheckRequest struct {

	// id
	ID string `json:"id,omitempty"`

	// Status from sub2 package (different type with same name)
	Sub2Status *ProtoSub2Status `json:"sub2Status,omitempty"`

	// Status from sub package
	SubStatus *ProtoSubStatus `json:"subStatus,omitempty"`
}

// Validate validates this examplepb status check request
func (m *ExamplepbStatusCheckRequest) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *ExamplepbStatusCheckRequest) validateSub2Status(formats strfmt.Registry) error {
	if swag.IsZero(m.Sub2Status) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

func (m *ExamplepbStatusCheckRequest) validateSubStatus(formats strfmt.Registry) error {
	if swag.IsZero(m.SubStatus) { // not required
		return nil
	}

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

			return err
		}
	}

	return nil
}

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

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

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

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

func (m *ExamplepbStatusCheckRequest) contextValidateSub2Status(ctx context.Context, formats strfmt.Registry) error {

	if m.Sub2Status != nil {

		if swag.IsZero(m.Sub2Status) { // not required
			return nil
		}

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

			return err
		}
	}

	return nil
}

func (m *ExamplepbStatusCheckRequest) contextValidateSubStatus(ctx context.Context, formats strfmt.Registry) error {

	if m.SubStatus != nil {

		if swag.IsZero(m.SubStatus) { // not required
			return nil
		}

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

			return err
		}
	}

	return nil
}

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

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