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

// APICreateDeviceProfileTemplateRequest api create device profile template request
//
// swagger:model apiCreateDeviceProfileTemplateRequest
type APICreateDeviceProfileTemplateRequest struct {

	// Object to create.
	DeviceProfileTemplate *APIDeviceProfileTemplate `json:"deviceProfileTemplate,omitempty"`
}

// Validate validates this api create device profile template request
func (m *APICreateDeviceProfileTemplateRequest) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *APICreateDeviceProfileTemplateRequest) validateDeviceProfileTemplate(formats strfmt.Registry) error {
	if swag.IsZero(m.DeviceProfileTemplate) { // not required
		return nil
	}

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

	return nil
}

// ContextValidate validate this api create device profile template request based on the context it is used
func (m *APICreateDeviceProfileTemplateRequest) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

func (m *APICreateDeviceProfileTemplateRequest) contextValidateDeviceProfileTemplate(ctx context.Context, formats strfmt.Registry) error {

	if m.DeviceProfileTemplate != nil {

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

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

	return nil
}

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

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