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

// CommonDTCECU common d t c e c u
//
// swagger:model common.DTC_ECU
type CommonDTCECU struct {

	// created at
	CreatedAt string `json:"created_at,omitempty"`

	// ecu name
	// Required: true
	EcuName *string `json:"ecu_name"`

	// epoch usec
	EpochUsec string `json:"epoch_usec,omitempty"`

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

	// mileage
	Mileage int64 `json:"mileage,omitempty"`

	// snapshot
	Snapshot string `json:"snapshot,omitempty"`

	// speed
	Speed int64 `json:"speed,omitempty"`

	// status byte
	StatusByte int64 `json:"status_byte,omitempty"`

	// status byte meaning
	StatusByteMeaning []string `json:"status_byte_meaning"`

	// trouble code
	TroubleCode int64 `json:"trouble_code,omitempty"`

	// trouble code information
	TroubleCodeInformation *CommonDTCInformation `json:"trouble_code_information,omitempty"`

	// vin
	Vin string `json:"vin,omitempty"`

	// voltage
	Voltage int64 `json:"voltage,omitempty"`
}

// Validate validates this common d t c e c u
func (m *CommonDTCECU) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

func (m *CommonDTCECU) validateEcuName(formats strfmt.Registry) error {

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

	return nil
}

func (m *CommonDTCECU) validateTroubleCodeInformation(formats strfmt.Registry) error {
	if swag.IsZero(m.TroubleCodeInformation) { // not required
		return nil
	}

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

	return nil
}

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

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

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

func (m *CommonDTCECU) contextValidateTroubleCodeInformation(ctx context.Context, formats strfmt.Registry) error {

	if m.TroubleCodeInformation != nil {

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

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

	return nil
}

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

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