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

package types

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

import (
	"context"
	"strconv"

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

// PublicHTTPValidationError public Http validation error
//
// swagger:model publicHttpValidationError
type PublicHTTPValidationError struct {
	PublicHTTPError

	// List of errors received while validating payload against schema
	// Required: true
	ValidationErrors []*HTTPValidationErrorDetail `json:"validationErrors"`
}

// UnmarshalJSON unmarshals this object from a JSON structure
func (m *PublicHTTPValidationError) UnmarshalJSON(raw []byte) error {
	// AO0
	var aO0 PublicHTTPError
	if err := swag.ReadJSON(raw, &aO0); err != nil {
		return err
	}
	m.PublicHTTPError = aO0

	// now for regular properties
	var propsPublicHTTPValidationError struct {
		ValidationErrors []*HTTPValidationErrorDetail `json:"validationErrors"`
	}
	if err := swag.ReadJSON(raw, &propsPublicHTTPValidationError); err != nil {
		return err
	}
	m.ValidationErrors = propsPublicHTTPValidationError.ValidationErrors

	return nil
}

// MarshalJSON marshals this object to a JSON structure
func (m PublicHTTPValidationError) MarshalJSON() ([]byte, error) {
	_parts := make([][]byte, 0, 1)

	aO0, err := swag.WriteJSON(m.PublicHTTPError)
	if err != nil {
		return nil, err
	}
	_parts = append(_parts, aO0)

	// now for regular properties
	var propsPublicHTTPValidationError struct {
		ValidationErrors []*HTTPValidationErrorDetail `json:"validationErrors"`
	}
	propsPublicHTTPValidationError.ValidationErrors = m.ValidationErrors

	jsonDataPropsPublicHTTPValidationError, errPublicHTTPValidationError := swag.WriteJSON(propsPublicHTTPValidationError)
	if errPublicHTTPValidationError != nil {
		return nil, errPublicHTTPValidationError
	}
	_parts = append(_parts, jsonDataPropsPublicHTTPValidationError)
	return swag.ConcatJSON(_parts...), nil
}

// Validate validates this public Http validation error
func (m *PublicHTTPValidationError) Validate(formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with PublicHTTPError
	if err := m.PublicHTTPError.Validate(formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *PublicHTTPValidationError) validateValidationErrors(formats strfmt.Registry) error {

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

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

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

	}

	return nil
}

// ContextValidate validate this public Http validation error based on the context it is used
func (m *PublicHTTPValidationError) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

	// validation for a type composition with PublicHTTPError
	if err := m.PublicHTTPError.ContextValidate(ctx, formats); err != nil {
		res = append(res, err)
	}

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

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

func (m *PublicHTTPValidationError) contextValidateValidationErrors(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

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

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