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

// NetAppAutoDiscoveryMethod net app auto discovery method
//
// swagger:model NetAppAutoDiscoveryMethod
type NetAppAutoDiscoveryMethod struct {

	// instance description
	InstanceDescription string `json:"instanceDescription,omitempty"`

	// instance group name
	InstanceGroupName string `json:"instanceGroupName,omitempty"`

	// instance locator
	InstanceLocator string `json:"instanceLocator,omitempty"`

	// instance name
	InstanceName string `json:"instanceName,omitempty"`

	// instance value
	InstanceValue string `json:"instanceValue,omitempty"`

	// object
	Object string `json:"object,omitempty"`

	// request
	Request string `json:"request,omitempty"`

	// type
	// Required: true
	Type *string `json:"type"`
}

// Name gets the name of this subtype
func (m *NetAppAutoDiscoveryMethod) Name() string {
	return "ad_netapp"
}

// SetName sets the name of this subtype
func (m *NetAppAutoDiscoveryMethod) SetName(val string) {
}

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

		// instance description
		InstanceDescription string `json:"instanceDescription,omitempty"`

		// instance group name
		InstanceGroupName string `json:"instanceGroupName,omitempty"`

		// instance locator
		InstanceLocator string `json:"instanceLocator,omitempty"`

		// instance name
		InstanceName string `json:"instanceName,omitempty"`

		// instance value
		InstanceValue string `json:"instanceValue,omitempty"`

		// object
		Object string `json:"object,omitempty"`

		// request
		Request string `json:"request,omitempty"`

		// type
		// Required: true
		Type *string `json:"type"`
	}
	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.*/

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

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

	var result NetAppAutoDiscoveryMethod

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

	result.InstanceDescription = data.InstanceDescription
	result.InstanceGroupName = data.InstanceGroupName
	result.InstanceLocator = data.InstanceLocator
	result.InstanceName = data.InstanceName
	result.InstanceValue = data.InstanceValue
	result.Object = data.Object
	result.Request = data.Request
	result.Type = data.Type

	*m = result

	return nil
}

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

		// instance description
		InstanceDescription string `json:"instanceDescription,omitempty"`

		// instance group name
		InstanceGroupName string `json:"instanceGroupName,omitempty"`

		// instance locator
		InstanceLocator string `json:"instanceLocator,omitempty"`

		// instance name
		InstanceName string `json:"instanceName,omitempty"`

		// instance value
		InstanceValue string `json:"instanceValue,omitempty"`

		// object
		Object string `json:"object,omitempty"`

		// request
		Request string `json:"request,omitempty"`

		// type
		// Required: true
		Type *string `json:"type"`
	}{

		InstanceDescription: m.InstanceDescription,

		InstanceGroupName: m.InstanceGroupName,

		InstanceLocator: m.InstanceLocator,

		InstanceName: m.InstanceName,

		InstanceValue: m.InstanceValue,

		Object: m.Object,

		Request: m.Request,

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

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

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

// Validate validates this net app auto discovery method
func (m *NetAppAutoDiscoveryMethod) Validate(formats strfmt.Registry) error {
	var res []error

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

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

func (m *NetAppAutoDiscoveryMethod) validateType(formats strfmt.Registry) error {

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

	return nil
}

// ContextValidate validate this net app auto discovery method based on the context it is used
func (m *NetAppAutoDiscoveryMethod) 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 *NetAppAutoDiscoveryMethod) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

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