// 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 (
	"bytes"
	"context"
	"encoding/json"

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

// DeviceNOCItem device n o c item
//
// swagger:model DeviceNOCItem
type DeviceNOCItem struct {

	// data point name
	// Required: true
	DataPointName *string `json:"dataPointName"`

	// data source display name
	// Required: true
	DataSourceDisplayName *string `json:"dataSourceDisplayName"`

	// device display name
	// Required: true
	DeviceDisplayName *string `json:"deviceDisplayName"`

	// device group full path
	// Required: true
	DeviceGroupFullPath *string `json:"deviceGroupFullPath"`

	// group by
	GroupBy string `json:"groupBy,omitempty"`

	// instance name
	// Required: true
	InstanceName *string `json:"instanceName"`

	// name
	// Required: true
	Name *string `json:"name"`
}

// Type gets the type of this subtype
func (m *DeviceNOCItem) Type() string {
	return "device"
}

// SetType sets the type of this subtype
func (m *DeviceNOCItem) SetType(val string) {
}

// UnmarshalJSON unmarshals this object with a polymorphic type from a JSON structure
func (m *DeviceNOCItem) UnmarshalJSON(raw []byte) error {
	var data struct {

		// data point name
		// Required: true
		DataPointName *string `json:"dataPointName"`

		// data source display name
		// Required: true
		DataSourceDisplayName *string `json:"dataSourceDisplayName"`

		// device display name
		// Required: true
		DeviceDisplayName *string `json:"deviceDisplayName"`

		// device group full path
		// Required: true
		DeviceGroupFullPath *string `json:"deviceGroupFullPath"`

		// group by
		GroupBy string `json:"groupBy,omitempty"`

		// instance name
		// Required: true
		InstanceName *string `json:"instanceName"`

		// name
		// Required: true
		Name *string `json:"name"`
	}
	buf := bytes.NewBuffer(raw)
	dec := json.NewDecoder(buf)
	dec.UseNumber()

	if err := dec.Decode(&data); err != nil {
		return err
	}

	var base struct {
		/* Just the base type fields. Used for unmashalling polymorphic types.*/

		Type string `json:"type"`
	}
	buf = bytes.NewBuffer(raw)
	dec = json.NewDecoder(buf)
	dec.UseNumber()

	if err := dec.Decode(&base); err != nil {
		return err
	}

	var result DeviceNOCItem

	if base.Type != result.Type() {
		/* Not the type we're looking for. */
		return errors.New(422, "invalid type value: %q", base.Type)
	}

	result.DataPointName = data.DataPointName
	result.DataSourceDisplayName = data.DataSourceDisplayName
	result.DeviceDisplayName = data.DeviceDisplayName
	result.DeviceGroupFullPath = data.DeviceGroupFullPath
	result.GroupBy = data.GroupBy
	result.InstanceName = data.InstanceName
	result.Name = data.Name

	*m = result

	return nil
}

// MarshalJSON marshals this object with a polymorphic type to a JSON structure
func (m DeviceNOCItem) MarshalJSON() ([]byte, error) {
	var b1, b2, b3 []byte
	var err error
	b1, err = json.Marshal(struct {

		// data point name
		// Required: true
		DataPointName *string `json:"dataPointName"`

		// data source display name
		// Required: true
		DataSourceDisplayName *string `json:"dataSourceDisplayName"`

		// device display name
		// Required: true
		DeviceDisplayName *string `json:"deviceDisplayName"`

		// device group full path
		// Required: true
		DeviceGroupFullPath *string `json:"deviceGroupFullPath"`

		// group by
		GroupBy string `json:"groupBy,omitempty"`

		// instance name
		// Required: true
		InstanceName *string `json:"instanceName"`

		// name
		// Required: true
		Name *string `json:"name"`
	}{

		DataPointName: m.DataPointName,

		DataSourceDisplayName: m.DataSourceDisplayName,

		DeviceDisplayName: m.DeviceDisplayName,

		DeviceGroupFullPath: m.DeviceGroupFullPath,

		GroupBy: m.GroupBy,

		InstanceName: m.InstanceName,

		Name: m.Name,
	})
	if err != nil {
		return nil, err
	}
	b2, err = json.Marshal(struct {
		Type string `json:"type"`
	}{

		Type: m.Type(),
	})
	if err != nil {
		return nil, err
	}

	return swag.ConcatJSON(b1, b2, b3), nil
}

// Validate validates this device n o c item
func (m *DeviceNOCItem) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

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

func (m *DeviceNOCItem) validateDataPointName(formats strfmt.Registry) error {

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

	return nil
}

func (m *DeviceNOCItem) validateDataSourceDisplayName(formats strfmt.Registry) error {

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

	return nil
}

func (m *DeviceNOCItem) validateDeviceDisplayName(formats strfmt.Registry) error {

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

	return nil
}

func (m *DeviceNOCItem) validateDeviceGroupFullPath(formats strfmt.Registry) error {

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

	return nil
}

func (m *DeviceNOCItem) validateInstanceName(formats strfmt.Registry) error {

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

	return nil
}

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

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

	return nil
}

// ContextValidate validate this device n o c item based on the context it is used
func (m *DeviceNOCItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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