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

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

// AzureRssEventSource azure rss event source
//
// swagger:model AzureRssEventSource
type AzureRssEventSource struct {
	alertBodyTemplateField string

	alertEffectiveIvalField *int32

	alertLevelField string

	alertSubjectTemplateField string

	appliesToField string

	clearAfterAckField bool

	descriptionField string

	filtersField []*RestEventSourceFilter

	groupField string

	idField int32

	nameField *string

	suppressDuplicatesESField bool

	tagsField string

	technologyField string

	versionField int64

	// The polling interval for the EventSource
	Schedule int32 `json:"schedule,omitempty"`
}

// AlertBodyTemplate gets the alert body template of this subtype
func (m *AzureRssEventSource) AlertBodyTemplate() string {
	return m.alertBodyTemplateField
}

// SetAlertBodyTemplate sets the alert body template of this subtype
func (m *AzureRssEventSource) SetAlertBodyTemplate(val string) {
	m.alertBodyTemplateField = val
}

// AlertEffectiveIval gets the alert effective ival of this subtype
func (m *AzureRssEventSource) AlertEffectiveIval() *int32 {
	return m.alertEffectiveIvalField
}

// SetAlertEffectiveIval sets the alert effective ival of this subtype
func (m *AzureRssEventSource) SetAlertEffectiveIval(val *int32) {
	m.alertEffectiveIvalField = val
}

// AlertLevel gets the alert level of this subtype
func (m *AzureRssEventSource) AlertLevel() string {
	return m.alertLevelField
}

// SetAlertLevel sets the alert level of this subtype
func (m *AzureRssEventSource) SetAlertLevel(val string) {
	m.alertLevelField = val
}

// AlertSubjectTemplate gets the alert subject template of this subtype
func (m *AzureRssEventSource) AlertSubjectTemplate() string {
	return m.alertSubjectTemplateField
}

// SetAlertSubjectTemplate sets the alert subject template of this subtype
func (m *AzureRssEventSource) SetAlertSubjectTemplate(val string) {
	m.alertSubjectTemplateField = val
}

// AppliesTo gets the applies to of this subtype
func (m *AzureRssEventSource) AppliesTo() string {
	return m.appliesToField
}

// SetAppliesTo sets the applies to of this subtype
func (m *AzureRssEventSource) SetAppliesTo(val string) {
	m.appliesToField = val
}

// ClearAfterAck gets the clear after ack of this subtype
func (m *AzureRssEventSource) ClearAfterAck() bool {
	return m.clearAfterAckField
}

// SetClearAfterAck sets the clear after ack of this subtype
func (m *AzureRssEventSource) SetClearAfterAck(val bool) {
	m.clearAfterAckField = val
}

// Collector gets the collector of this subtype
func (m *AzureRssEventSource) Collector() string {
	return "azurerss"
}

// SetCollector sets the collector of this subtype
func (m *AzureRssEventSource) SetCollector(val string) {
}

// Description gets the description of this subtype
func (m *AzureRssEventSource) Description() string {
	return m.descriptionField
}

// SetDescription sets the description of this subtype
func (m *AzureRssEventSource) SetDescription(val string) {
	m.descriptionField = val
}

// Filters gets the filters of this subtype
func (m *AzureRssEventSource) Filters() []*RestEventSourceFilter {
	return m.filtersField
}

// SetFilters sets the filters of this subtype
func (m *AzureRssEventSource) SetFilters(val []*RestEventSourceFilter) {
	m.filtersField = val
}

// Group gets the group of this subtype
func (m *AzureRssEventSource) Group() string {
	return m.groupField
}

// SetGroup sets the group of this subtype
func (m *AzureRssEventSource) SetGroup(val string) {
	m.groupField = val
}

// ID gets the id of this subtype
func (m *AzureRssEventSource) ID() int32 {
	return m.idField
}

// SetID sets the id of this subtype
func (m *AzureRssEventSource) SetID(val int32) {
	m.idField = val
}

// Name gets the name of this subtype
func (m *AzureRssEventSource) Name() *string {
	return m.nameField
}

// SetName sets the name of this subtype
func (m *AzureRssEventSource) SetName(val *string) {
	m.nameField = val
}

// SuppressDuplicatesES gets the suppress duplicates e s of this subtype
func (m *AzureRssEventSource) SuppressDuplicatesES() bool {
	return m.suppressDuplicatesESField
}

// SetSuppressDuplicatesES sets the suppress duplicates e s of this subtype
func (m *AzureRssEventSource) SetSuppressDuplicatesES(val bool) {
	m.suppressDuplicatesESField = val
}

// Tags gets the tags of this subtype
func (m *AzureRssEventSource) Tags() string {
	return m.tagsField
}

// SetTags sets the tags of this subtype
func (m *AzureRssEventSource) SetTags(val string) {
	m.tagsField = val
}

// Technology gets the technology of this subtype
func (m *AzureRssEventSource) Technology() string {
	return m.technologyField
}

// SetTechnology sets the technology of this subtype
func (m *AzureRssEventSource) SetTechnology(val string) {
	m.technologyField = val
}

// Version gets the version of this subtype
func (m *AzureRssEventSource) Version() int64 {
	return m.versionField
}

// SetVersion sets the version of this subtype
func (m *AzureRssEventSource) SetVersion(val int64) {
	m.versionField = val
}

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

		// The polling interval for the EventSource
		Schedule int32 `json:"schedule,omitempty"`
	}
	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.*/

		AlertBodyTemplate string `json:"alertBodyTemplate,omitempty"`

		AlertEffectiveIval *int32 `json:"alertEffectiveIval"`

		AlertLevel string `json:"alertLevel,omitempty"`

		AlertSubjectTemplate string `json:"alertSubjectTemplate,omitempty"`

		AppliesTo string `json:"appliesTo,omitempty"`

		ClearAfterAck bool `json:"clearAfterAck,omitempty"`

		Collector string `json:"collector,omitempty"`

		Description string `json:"description,omitempty"`

		Filters []*RestEventSourceFilter `json:"filters,omitempty"`

		Group string `json:"group,omitempty"`

		ID int32 `json:"id"`

		Name *string `json:"name"`

		SuppressDuplicatesES bool `json:"suppressDuplicatesES,omitempty"`

		Tags string `json:"tags,omitempty"`

		Technology string `json:"technology,omitempty"`

		Version int64 `json:"version,omitempty"`
	}
	buf = bytes.NewBuffer(raw)
	dec = json.NewDecoder(buf)
	dec.UseNumber()

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

	var result AzureRssEventSource

	result.alertBodyTemplateField = base.AlertBodyTemplate

	result.alertEffectiveIvalField = base.AlertEffectiveIval

	result.alertLevelField = base.AlertLevel

	result.alertSubjectTemplateField = base.AlertSubjectTemplate

	result.appliesToField = base.AppliesTo

	result.clearAfterAckField = base.ClearAfterAck

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

	result.filtersField = base.Filters

	result.groupField = base.Group

	result.idField = base.ID

	result.nameField = base.Name

	result.suppressDuplicatesESField = base.SuppressDuplicatesES

	result.tagsField = base.Tags

	result.technologyField = base.Technology

	result.versionField = base.Version

	result.Schedule = data.Schedule

	*m = result

	return nil
}

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

		// The polling interval for the EventSource
		Schedule int32 `json:"schedule,omitempty"`
	}{

		Schedule: m.Schedule,
	})
	if err != nil {
		return nil, err
	}
	b2, err = json.Marshal(struct {
		AlertBodyTemplate string `json:"alertBodyTemplate,omitempty"`

		AlertEffectiveIval *int32 `json:"alertEffectiveIval"`

		AlertLevel string `json:"alertLevel,omitempty"`

		AlertSubjectTemplate string `json:"alertSubjectTemplate,omitempty"`

		AppliesTo string `json:"appliesTo,omitempty"`

		ClearAfterAck bool `json:"clearAfterAck,omitempty"`

		Collector string `json:"collector,omitempty"`

		Description string `json:"description,omitempty"`

		Filters []*RestEventSourceFilter `json:"filters,omitempty"`

		Group string `json:"group,omitempty"`

		ID int32 `json:"id"`

		Name *string `json:"name"`

		SuppressDuplicatesES bool `json:"suppressDuplicatesES,omitempty"`

		Tags string `json:"tags,omitempty"`

		Technology string `json:"technology,omitempty"`

		Version int64 `json:"version,omitempty"`
	}{

		AlertBodyTemplate: m.AlertBodyTemplate(),

		AlertEffectiveIval: m.AlertEffectiveIval(),

		AlertLevel: m.AlertLevel(),

		AlertSubjectTemplate: m.AlertSubjectTemplate(),

		AppliesTo: m.AppliesTo(),

		ClearAfterAck: m.ClearAfterAck(),

		Collector: m.Collector(),

		Description: m.Description(),

		Filters: m.Filters(),

		Group: m.Group(),

		ID: m.ID(),

		Name: m.Name(),

		SuppressDuplicatesES: m.SuppressDuplicatesES(),

		Tags: m.Tags(),

		Technology: m.Technology(),

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

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

// Validate validates this azure rss event source
func (m *AzureRssEventSource) Validate(formats strfmt.Registry) error {
	var res []error

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

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

	if err := m.validateID(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 *AzureRssEventSource) validateAlertEffectiveIval(formats strfmt.Registry) error {

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

	return nil
}

func (m *AzureRssEventSource) validateFilters(formats strfmt.Registry) error {

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

	for i := 0; i < len(m.Filters()); i++ {
		if swag.IsZero(m.filtersField[i]) { // not required
			continue
		}

		if m.filtersField[i] != nil {
			if err := m.filtersField[i].Validate(formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("filters" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *AzureRssEventSource) validateID(formats strfmt.Registry) error {

	if err := validate.Required("id", "body", int32(m.ID())); err != nil {
		return err
	}

	return nil
}

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

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

	return nil
}

// ContextValidate validate this azure rss event source based on the context it is used
func (m *AzureRssEventSource) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	var res []error

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

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

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

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

func (m *AzureRssEventSource) contextValidateFilters(ctx context.Context, formats strfmt.Registry) error {

	for i := 0; i < len(m.Filters()); i++ {

		if m.filtersField[i] != nil {
			if err := m.filtersField[i].ContextValidate(ctx, formats); err != nil {
				if ve, ok := err.(*errors.Validation); ok {
					return ve.ValidateName("filters" + "." + strconv.Itoa(i))
				}
				return err
			}
		}

	}

	return nil
}

func (m *AzureRssEventSource) contextValidateID(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "id", "body", int32(m.ID())); err != nil {
		return err
	}

	return nil
}

func (m *AzureRssEventSource) contextValidateVersion(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "version", "body", int64(m.Version())); err != nil {
		return err
	}

	return nil
}

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

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