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

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

// CommonCarFlashpackVersionAddRequest common car flashpack version add request
//
// swagger:model common.CarFlashpackVersionAddRequest
type CommonCarFlashpackVersionAddRequest struct {

	// car model
	// Required: true
	CarModel *string `json:"car_model"`

	// car trim
	// Required: true
	CarTrim *string `json:"car_trim"`

	// car year
	// Required: true
	CarYear *int64 `json:"car_year"`

	// ecu versions
	// Required: true
	EcuVersions []*CommonECUVersionRequest `json:"ecu_versions"`

	// flashpack
	// Required: true
	Flashpack *string `json:"flashpack"`

	// os version
	OsVersion string `json:"os_version,omitempty"`
}

// Validate validates this common car flashpack version add request
func (m *CommonCarFlashpackVersionAddRequest) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *CommonCarFlashpackVersionAddRequest) validateCarModel(formats strfmt.Registry) error {

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

	return nil
}

func (m *CommonCarFlashpackVersionAddRequest) validateCarTrim(formats strfmt.Registry) error {

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

	return nil
}

func (m *CommonCarFlashpackVersionAddRequest) validateCarYear(formats strfmt.Registry) error {

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

	return nil
}

func (m *CommonCarFlashpackVersionAddRequest) validateEcuVersions(formats strfmt.Registry) error {

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

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

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

	}

	return nil
}

func (m *CommonCarFlashpackVersionAddRequest) validateFlashpack(formats strfmt.Registry) error {

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

	return nil
}

// ContextValidate validate this common car flashpack version add request based on the context it is used
func (m *CommonCarFlashpackVersionAddRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *CommonCarFlashpackVersionAddRequest) contextValidateEcuVersions(ctx context.Context, formats strfmt.Registry) error {

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

		if m.EcuVersions[i] != nil {

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

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

	}

	return nil
}

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

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