// 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"
	"io"
	"io/ioutil"

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

// AutoDiscoveryMethod auto discovery method
//
// swagger:discriminator AutoDiscoveryMethod name
type AutoDiscoveryMethod interface {
	runtime.Validatable
	runtime.ContextValidatable

	// name
	// Required: true
	Name() string
	SetName(string)

	// AdditionalProperties in base type shoud be handled just like regular properties
	// At this moment, the base type property is pushed down to the subtype
}

type autoDiscoveryMethod struct {
	nameField string
}

// Name gets the name of this polymorphic type
func (m *autoDiscoveryMethod) Name() string {
	return "AutoDiscoveryMethod"
}

// SetName sets the name of this polymorphic type
func (m *autoDiscoveryMethod) SetName(val string) {
}

// UnmarshalAutoDiscoveryMethodSlice unmarshals polymorphic slices of AutoDiscoveryMethod
func UnmarshalAutoDiscoveryMethodSlice(reader io.Reader, consumer runtime.Consumer) ([]AutoDiscoveryMethod, error) {
	var elements []json.RawMessage
	if err := consumer.Consume(reader, &elements); err != nil {
		return nil, err
	}

	var result []AutoDiscoveryMethod
	for _, element := range elements {
		obj, err := unmarshalAutoDiscoveryMethod(element, consumer)
		if err != nil {
			return nil, err
		}
		result = append(result, obj)
	}
	return result, nil
}

// UnmarshalAutoDiscoveryMethod unmarshals polymorphic AutoDiscoveryMethod
func UnmarshalAutoDiscoveryMethod(reader io.Reader, consumer runtime.Consumer) (AutoDiscoveryMethod, error) {
	// we need to read this twice, so first into a buffer
	data, err := ioutil.ReadAll(reader)
	if err != nil {
		return nil, err
	}
	return unmarshalAutoDiscoveryMethod(data, consumer)
}

func unmarshalAutoDiscoveryMethod(data []byte, consumer runtime.Consumer) (AutoDiscoveryMethod, error) {
	buf := bytes.NewBuffer(data)
	buf2 := bytes.NewBuffer(data)

	// the first time this is read is to fetch the value of the name property.
	var getType struct {
		Name string `json:"name"`
	}
	if err := consumer.Consume(buf, &getType); err != nil {
		return nil, err
	}

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

	// The value of name is used to determine which type to create and unmarshal the data into
	switch getType.Name {
	case "AutoDiscoveryMethod":
		var result autoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "GcpAppEngineDiscoveryMethod":
		var result GcpAppEngineDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "GcpBillingDiscoveryMethod":
		var result GcpBillingDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "OpenMetricDiscoveryMethod":
		var result OpenMetricDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsbillingreport":
		var result AwsBillingReportDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsec2reservedinstance":
		var result AwsEC2ReservedInstanceDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsec2reservedinstancecoverage":
		var result AwsEC2ReservedInstanceCoverageDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsec2scheduledevents":
		var result EC2ScheduledEventAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsecsservice":
		var result AwsEcsServiceDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awselasticache":
		var result AwsElastiCacheDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awslbtargetgroups":
		var result AwsLBTargetGroupDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsredshift":
		var result AwsRedShiftDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_awsserviceregion":
		var result AwsServiceRegionDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_azurebilling":
		var result AzureBillingDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_azurerediscache":
		var result AzureRedisCacheDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_azureserviceregion":
		var result AzureServiceRegionDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_azuresubscription":
		var result AzureSubscriptionDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_cim":
		var result CIMAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_cloudwatch":
		var result CloudWatchAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_collector":
		var result CollectorAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_dummy":
		var result DummyAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_ec2":
		var result EC2AutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_esx":
		var result ESXAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_http":
		var result HTTPAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_ipmi":
		var result IPMIAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_jdbc":
		var result JDBCAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_jmx":
		var result JMXAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_mongo":
		var result MongoAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_netapp":
		var result NetAppAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_pdh":
		var result PDHAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_port":
		var result PortAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_script":
		var result ScriptAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_sdkscript":
		var result SDKScriptDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_snmp":
		var result SNMPAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_wmi":
		var result WMIAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "ad_xen":
		var result XENAutoDiscoveryMethod
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	}
	return nil, errors.New(422, "invalid name value: %q", getType.Name)
}

// Validate validates this auto discovery method
func (m *autoDiscoveryMethod) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this auto discovery method based on context it is used
func (m *autoDiscoveryMethod) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}
