// 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 (
	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// Thing thing
//
// swagger:model Thing
type Thing struct {

	// category
	Category Category `json:"category,omitempty"`

	// created at
	// Format: date-time
	CreatedAt strfmt.DateTime `json:"createdAt,omitempty"`

	// hash nullable
	HashNullable *string `json:"hashNullable,omitempty"`

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

	// name
	Name string `json:"name,omitempty"`

	// nested object
	NestedObject *Object `json:"nestedObject,omitempty"`

	// range nullable
	// Format: date-time
	RangeNullable *strfmt.DateTime `json:"rangeNullable,omitempty"`

	// version
	Version int64 `json:"version,omitempty"`
}

// Validate validates this thing
func (m *Thing) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

func (m *Thing) validateCategory(formats strfmt.Registry) error {

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

	if err := m.Category.Validate(formats); err != nil {
		if ve, ok := err.(*errors.Validation); ok {
			return ve.ValidateName("category")
		}
		return err
	}

	return nil
}

func (m *Thing) validateCreatedAt(formats strfmt.Registry) error {

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

	if err := validate.FormatOf("createdAt", "body", "date-time", m.CreatedAt.String(), formats); err != nil {
		return err
	}

	return nil
}

func (m *Thing) validateNestedObject(formats strfmt.Registry) error {

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

	if m.NestedObject != nil {
		if err := m.NestedObject.Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("nestedObject")
			}
			return err
		}
	}

	return nil
}

func (m *Thing) validateRangeNullable(formats strfmt.Registry) error {

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

	if err := validate.FormatOf("rangeNullable", "body", "date-time", m.RangeNullable.String(), formats); err != nil {
		return err
	}

	return nil
}

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

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