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

// OpsNoteScope ops note scope
//
// swagger:discriminator OpsNoteScope type
type OpsNoteScope interface {
	runtime.Validatable
	runtime.ContextValidatable

	// type
	// Example: device
	// Required: true
	Type() string
	SetType(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 opsNoteScope struct {
	typeField string
}

// Type gets the type of this polymorphic type
func (m *opsNoteScope) Type() string {
	return "OpsNoteScope"
}

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

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

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

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

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

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

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

	// The value of type is used to determine which type to create and unmarshal the data into
	switch getType.Type {
	case "OpsNoteScope":
		var result opsNoteScope
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "device":
		var result OpsNoteDeviceScope
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "deviceGroup":
		var result OpsNoteDeviceGroupScope
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "groupAll":
		var result OpsNoteGroupAllScope
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "website":
		var result OpsNoteWebsiteScope
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "websiteGroup":
		var result OpsNoteWebsiteGroupScope
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	}
	return nil, errors.New(422, "invalid type value: %q", getType.Type)
}

// Validate validates this ops note scope
func (m *opsNoteScope) Validate(formats strfmt.Registry) error {
	return nil
}

// ContextValidate validates this ops note scope based on context it is used
func (m *opsNoteScope) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}
