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

// CommonUpdateManifestECU common update manifest e c u
//
// swagger:model common.UpdateManifestECU
type CommonUpdateManifestECU struct {

	// configuration
	// Max Length: 5000
	Configuration string `json:"configuration,omitempty"`

	// configuration mask
	// Max Length: 5000
	ConfigurationMask string `json:"configuration_mask,omitempty"`

	// current version
	CurrentVersion string `json:"current_version,omitempty"`

	// ecc keys
	EccKeys *CommonECCKeys `json:"ecc_keys,omitempty"`

	// files
	Files []*CommonUpdateManifestFile `json:"files"`

	// hw version
	HwVersion string `json:"hw_version,omitempty"`

	// hw versions
	HwVersions []string `json:"hw_versions"`

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

	// install priority
	InstallPriority int64 `json:"install_priority,omitempty"`

	// manifest id
	// Required: true
	// Minimum: 0
	ManifestID *int64 `json:"manifest_id"`

	// mode
	// Required: true
	// Max Length: 4
	Mode *string `json:"mode"`

	// name
	// Required: true
	// Max Length: 10
	// Min Length: 2
	Name *string `json:"name"`

	// rollback
	Rollback []*CommonUpdateManifestECU `json:"rollback"`

	// self download
	SelfDownload bool `json:"self_download,omitempty"`

	// version
	// Required: true
	// Max Length: 255
	Version *string `json:"version"`
}

// Validate validates this common update manifest e c u
func (m *CommonUpdateManifestECU) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

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

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

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

func (m *CommonUpdateManifestECU) validateConfiguration(formats strfmt.Registry) error {
	if swag.IsZero(m.Configuration) { // not required
		return nil
	}

	if err := validate.MaxLength("configuration", "body", m.Configuration, 5000); err != nil {
		return err
	}

	return nil
}

func (m *CommonUpdateManifestECU) validateConfigurationMask(formats strfmt.Registry) error {
	if swag.IsZero(m.ConfigurationMask) { // not required
		return nil
	}

	if err := validate.MaxLength("configuration_mask", "body", m.ConfigurationMask, 5000); err != nil {
		return err
	}

	return nil
}

func (m *CommonUpdateManifestECU) validateEccKeys(formats strfmt.Registry) error {
	if swag.IsZero(m.EccKeys) { // not required
		return nil
	}

	if m.EccKeys != nil {
		if err := m.EccKeys.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("ecc_keys")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("ecc_keys")
			}
			return err
		}
	}

	return nil
}

func (m *CommonUpdateManifestECU) validateFiles(formats strfmt.Registry) error {
	if swag.IsZero(m.Files) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *CommonUpdateManifestECU) validateManifestID(formats strfmt.Registry) error {

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

	if err := validate.MinimumInt("manifest_id", "body", *m.ManifestID, 0, false); err != nil {
		return err
	}

	return nil
}

func (m *CommonUpdateManifestECU) validateMode(formats strfmt.Registry) error {

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

	if err := validate.MaxLength("mode", "body", *m.Mode, 4); err != nil {
		return err
	}

	return nil
}

func (m *CommonUpdateManifestECU) validateName(formats strfmt.Registry) error {

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

	if err := validate.MinLength("name", "body", *m.Name, 2); err != nil {
		return err
	}

	if err := validate.MaxLength("name", "body", *m.Name, 10); err != nil {
		return err
	}

	return nil
}

func (m *CommonUpdateManifestECU) validateRollback(formats strfmt.Registry) error {
	if swag.IsZero(m.Rollback) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *CommonUpdateManifestECU) validateVersion(formats strfmt.Registry) error {

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

	if err := validate.MaxLength("version", "body", *m.Version, 255); err != nil {
		return err
	}

	return nil
}

// ContextValidate validate this common update manifest e c u based on the context it is used
func (m *CommonUpdateManifestECU) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *CommonUpdateManifestECU) contextValidateEccKeys(ctx context.Context, formats strfmt.Registry) error {

	if m.EccKeys != nil {

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

		if err := m.EccKeys.ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("ecc_keys")
			} else if ce, ok := err.(*errors.CompositeError); ok {
				return ce.ValidateName("ecc_keys")
			}
			return err
		}
	}

	return nil
}

func (m *CommonUpdateManifestECU) contextValidateFiles(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Files[i] != nil {

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

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

	}

	return nil
}

func (m *CommonUpdateManifestECU) contextValidateRollback(ctx context.Context, formats strfmt.Registry) error {

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

		if m.Rollback[i] != nil {

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

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

	}

	return nil
}

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

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