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

package models

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

import (
	"context"

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

// HandlersJSONCarStateMultiMessage handlers JSON car state multi message
//
// swagger:model handlers.JSONCarStateMultiMessage
type HandlersJSONCarStateMultiMessage struct {

	// data
	Data map[string]CommonCarState `json:"data,omitempty"`

	// error list
	ErrorList []string `json:"errorList"`
}

// Validate validates this handlers JSON car state multi message
func (m *HandlersJSONCarStateMultiMessage) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *HandlersJSONCarStateMultiMessage) validateData(formats strfmt.Registry) error {
	if swag.IsZero(m.Data) { // not required
		return nil
	}

	for k := range m.Data {

		if err := validate.Required("data"+"."+k, "body", m.Data[k]); err != nil {
			return err
		}
		if val, ok := m.Data[k]; ok {
			if err := val.Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("data" + "." + k)
				} else if ce, ok := err.(*errors.CompositeError); ok {
					return ce.ValidateName("data" + "." + k)
				}
				return err
			}
		}

	}

	return nil
}

// ContextValidate validate this handlers JSON car state multi message based on the context it is used
func (m *HandlersJSONCarStateMultiMessage) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *HandlersJSONCarStateMultiMessage) contextValidateData(ctx context.Context, formats strfmt.Registry) error {

	for k := range m.Data {

		if val, ok := m.Data[k]; ok {
			if err := val.ContextValidate(ctx, formats); err != nil {
				return err
			}
		}

	}

	return nil
}

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

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