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

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

// Website website
//
// swagger:discriminator Website type
type Website interface {
	runtime.Validatable
	runtime.ContextValidatable

	// The checkpoints from the which the website is monitored. This object should reference each location specified in testLocation in addition to an 'Overall' checkpoint
	Checkpoints() []*WebsiteCheckPoint
	SetCheckpoints([]*WebsiteCheckPoint)

	// The collectors that are monitoring the website, if the website is internal
	// Read Only: true
	Collectors() []*WebsiteCollectorInfo
	SetCollectors([]*WebsiteCollectorInfo)

	// The description of the website
	// Example: Monitor Ebay site response times
	Description() string
	SetDescription(string)

	// true: alerting is disabled for the website
	// false: alerting is enabled for the website
	// If stopMonitoring=true, then alerting will also by default be disabled for the website
	DisableAlerting() bool
	SetDisableAlerting(bool)

	// The number of test locations that checks must fail at to trigger an alert, where the alert triggered will be consistent with the value of overallAlertLevel. Possible values and corresponding number of Site Monitor locations are
	// 0 : all
	// 1 : half
	// 2 : more than one
	// 3 : any
	// Example: 0
	GlobalSmAlertCond() int32
	SetGlobalSmAlertCond(int32)

	// The id of the group the website is in
	// Example: 1
	// Read Only: true
	GroupID() int32
	SetGroupID(int32)

	// The id of the website
	// Read Only: true
	ID() int32
	SetID(int32)

	// warn | error | critical
	// The level of alert to trigger if the website fails a check from an individual test location
	// Example: warn
	IndividualAlertLevel() string
	SetIndividualAlertLevel(string)

	// true: an alert will be triggered if a check fails from an individual test location
	// false: an alert will not be triggered if a check fails from an individual test location
	// Example: false
	IndividualSmAlertEnable() bool
	SetIndividualSmAlertEnable(bool)

	// Whether or not the website is internal
	// Example: false
	IsInternal() bool
	SetIsInternal(bool)

	// The time (in epoch format) that the website was updated
	// Read Only: true
	LastUpdated() int64
	SetLastUpdated(int64)

	// The name of the website
	// Example: Ebay
	// Required: true
	Name() *string
	SetName(*string)

	// warn | error | critical
	// The level of alert to trigger if the website fails the number of checks specified by transition from the test locations specified by globalSmAlertCond
	// Example: warn
	OverallAlertLevel() string
	SetOverallAlertLevel(string)

	// 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
	// The polling interval for the website, in units of minutes. This value indicates how often the website is checked. The minimum is 1 minute, and the maximum is 10 minutes
	// Example: 5
	PollingInterval() int32
	SetPollingInterval(int32)

	// The properties associated with the website
	// Read Only: true
	Properties() []*NameAndValue
	SetProperties([]*NameAndValue)

	// Whether is the website dead (the collector is down) or not
	// Read Only: true
	Status() string
	SetStatus(string)

	// true: monitoring is disabled for the website
	// false: monitoring is enabled for the website
	// If stopMonitoring=true, then alerting will also by default be disabled for the website
	StopMonitoring() bool
	SetStopMonitoring(bool)

	// true: monitoring is disabled for all services in the website's folder
	// false: monitoring is not disabled for all services in website's folder
	// Read Only: true
	StopMonitoringByFolder() *bool
	SetStopMonitoringByFolder(*bool)

	// The website template
	Template() interface{}
	SetTemplate(interface{})

	// The locations from which the website is monitored. If the website is internal, this field should include Collectors. If Non-Internal, possible test locations are:
	// 1 : US - LA
	// 2 : US - DC
	// 3 : US - SF
	// 4 : Europe - Dublin
	// 5 : Asia - Singapore
	// 6 : Australia - Sydney
	// testLocation:"{all:true}" indicates that the service will be monitored from all checkpoint locations
	// testLocation:"{smgIds:[1,2,3]}" indicates that the service will be monitored from checkpoint locations 1, 2 and 3
	// testLocation:"{collectorIds:[85,90]}" indicates that the service will be monitored by Collectors 85 and 90
	// Required: true
	TestLocation() *WebsiteLocation
	SetTestLocation(*WebsiteLocation)

	// 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 30 | 60
	// The number of checks that must fail before an alert is triggered
	// Example: 1
	Transition() int32
	SetTransition(int32)

	// The type of the website. Acceptable values are: pingcheck, webcheck
	// Example: webcheck
	// Required: true
	Type() string
	SetType(string)

	// true: The alert settings configured in the website Default Settings will be used
	// false: Service Default Settings will not be used, and you will need to specify individualSMAlertEnable, individualAlertLevel, globalSmAlertConf, overallAlertLevel and pollingInterval
	// Example: true
	UseDefaultAlertSetting() bool
	SetUseDefaultAlertSetting(bool)

	// true: The checkpoint locations configured in the website Default Settings will be used
	// false: The checkpoint locations specified in the testLocation will be used
	// Example: false
	UseDefaultLocationSetting() bool
	SetUseDefaultLocationSetting(bool)

	// write | read | ack. The permission level of the user that made the API request
	UserPermission() string
	SetUserPermission(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 website struct {
	checkpointsField []*WebsiteCheckPoint

	collectorsField []*WebsiteCollectorInfo

	descriptionField string

	disableAlertingField bool

	globalSmAlertCondField int32

	groupIdField int32

	idField int32

	individualAlertLevelField string

	individualSmAlertEnableField bool

	isInternalField bool

	lastUpdatedField int64

	nameField *string

	overallAlertLevelField string

	pollingIntervalField int32

	propertiesField []*NameAndValue

	statusField string

	stopMonitoringField bool

	stopMonitoringByFolderField *bool

	templateField interface{}

	testLocationField *WebsiteLocation

	transitionField int32

	typeField string

	useDefaultAlertSettingField bool

	useDefaultLocationSettingField bool

	userPermissionField string
}

// Checkpoints gets the checkpoints of this polymorphic type
func (m *website) Checkpoints() []*WebsiteCheckPoint {
	return m.checkpointsField
}

// SetCheckpoints sets the checkpoints of this polymorphic type
func (m *website) SetCheckpoints(val []*WebsiteCheckPoint) {
	m.checkpointsField = val
}

// Collectors gets the collectors of this polymorphic type
func (m *website) Collectors() []*WebsiteCollectorInfo {
	return m.collectorsField
}

// SetCollectors sets the collectors of this polymorphic type
func (m *website) SetCollectors(val []*WebsiteCollectorInfo) {
	m.collectorsField = val
}

// Description gets the description of this polymorphic type
func (m *website) Description() string {
	return m.descriptionField
}

// SetDescription sets the description of this polymorphic type
func (m *website) SetDescription(val string) {
	m.descriptionField = val
}

// DisableAlerting gets the disable alerting of this polymorphic type
func (m *website) DisableAlerting() bool {
	return m.disableAlertingField
}

// SetDisableAlerting sets the disable alerting of this polymorphic type
func (m *website) SetDisableAlerting(val bool) {
	m.disableAlertingField = val
}

// GlobalSmAlertCond gets the global sm alert cond of this polymorphic type
func (m *website) GlobalSmAlertCond() int32 {
	return m.globalSmAlertCondField
}

// SetGlobalSmAlertCond sets the global sm alert cond of this polymorphic type
func (m *website) SetGlobalSmAlertCond(val int32) {
	m.globalSmAlertCondField = val
}

// GroupID gets the group Id of this polymorphic type
func (m *website) GroupID() int32 {
	return m.groupIdField
}

// SetGroupID sets the group Id of this polymorphic type
func (m *website) SetGroupID(val int32) {
	m.groupIdField = val
}

// ID gets the id of this polymorphic type
func (m *website) ID() int32 {
	return m.idField
}

// SetID sets the id of this polymorphic type
func (m *website) SetID(val int32) {
	m.idField = val
}

// IndividualAlertLevel gets the individual alert level of this polymorphic type
func (m *website) IndividualAlertLevel() string {
	return m.individualAlertLevelField
}

// SetIndividualAlertLevel sets the individual alert level of this polymorphic type
func (m *website) SetIndividualAlertLevel(val string) {
	m.individualAlertLevelField = val
}

// IndividualSmAlertEnable gets the individual sm alert enable of this polymorphic type
func (m *website) IndividualSmAlertEnable() bool {
	return m.individualSmAlertEnableField
}

// SetIndividualSmAlertEnable sets the individual sm alert enable of this polymorphic type
func (m *website) SetIndividualSmAlertEnable(val bool) {
	m.individualSmAlertEnableField = val
}

// IsInternal gets the is internal of this polymorphic type
func (m *website) IsInternal() bool {
	return m.isInternalField
}

// SetIsInternal sets the is internal of this polymorphic type
func (m *website) SetIsInternal(val bool) {
	m.isInternalField = val
}

// LastUpdated gets the last updated of this polymorphic type
func (m *website) LastUpdated() int64 {
	return m.lastUpdatedField
}

// SetLastUpdated sets the last updated of this polymorphic type
func (m *website) SetLastUpdated(val int64) {
	m.lastUpdatedField = val
}

// Name gets the name of this polymorphic type
func (m *website) Name() *string {
	return m.nameField
}

// SetName sets the name of this polymorphic type
func (m *website) SetName(val *string) {
	m.nameField = val
}

// OverallAlertLevel gets the overall alert level of this polymorphic type
func (m *website) OverallAlertLevel() string {
	return m.overallAlertLevelField
}

// SetOverallAlertLevel sets the overall alert level of this polymorphic type
func (m *website) SetOverallAlertLevel(val string) {
	m.overallAlertLevelField = val
}

// PollingInterval gets the polling interval of this polymorphic type
func (m *website) PollingInterval() int32 {
	return m.pollingIntervalField
}

// SetPollingInterval sets the polling interval of this polymorphic type
func (m *website) SetPollingInterval(val int32) {
	m.pollingIntervalField = val
}

// Properties gets the properties of this polymorphic type
func (m *website) Properties() []*NameAndValue {
	return m.propertiesField
}

// SetProperties sets the properties of this polymorphic type
func (m *website) SetProperties(val []*NameAndValue) {
	m.propertiesField = val
}

// Status gets the status of this polymorphic type
func (m *website) Status() string {
	return m.statusField
}

// SetStatus sets the status of this polymorphic type
func (m *website) SetStatus(val string) {
	m.statusField = val
}

// StopMonitoring gets the stop monitoring of this polymorphic type
func (m *website) StopMonitoring() bool {
	return m.stopMonitoringField
}

// SetStopMonitoring sets the stop monitoring of this polymorphic type
func (m *website) SetStopMonitoring(val bool) {
	m.stopMonitoringField = val
}

// StopMonitoringByFolder gets the stop monitoring by folder of this polymorphic type
func (m *website) StopMonitoringByFolder() *bool {
	return m.stopMonitoringByFolderField
}

// SetStopMonitoringByFolder sets the stop monitoring by folder of this polymorphic type
func (m *website) SetStopMonitoringByFolder(val *bool) {
	m.stopMonitoringByFolderField = val
}

// Template gets the template of this polymorphic type
func (m *website) Template() interface{} {
	return m.templateField
}

// SetTemplate sets the template of this polymorphic type
func (m *website) SetTemplate(val interface{}) {
	m.templateField = val
}

// TestLocation gets the test location of this polymorphic type
func (m *website) TestLocation() *WebsiteLocation {
	return m.testLocationField
}

// SetTestLocation sets the test location of this polymorphic type
func (m *website) SetTestLocation(val *WebsiteLocation) {
	m.testLocationField = val
}

// Transition gets the transition of this polymorphic type
func (m *website) Transition() int32 {
	return m.transitionField
}

// SetTransition sets the transition of this polymorphic type
func (m *website) SetTransition(val int32) {
	m.transitionField = val
}

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

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

// UseDefaultAlertSetting gets the use default alert setting of this polymorphic type
func (m *website) UseDefaultAlertSetting() bool {
	return m.useDefaultAlertSettingField
}

// SetUseDefaultAlertSetting sets the use default alert setting of this polymorphic type
func (m *website) SetUseDefaultAlertSetting(val bool) {
	m.useDefaultAlertSettingField = val
}

// UseDefaultLocationSetting gets the use default location setting of this polymorphic type
func (m *website) UseDefaultLocationSetting() bool {
	return m.useDefaultLocationSettingField
}

// SetUseDefaultLocationSetting sets the use default location setting of this polymorphic type
func (m *website) SetUseDefaultLocationSetting(val bool) {
	m.useDefaultLocationSettingField = val
}

// UserPermission gets the user permission of this polymorphic type
func (m *website) UserPermission() string {
	return m.userPermissionField
}

// SetUserPermission sets the user permission of this polymorphic type
func (m *website) SetUserPermission(val string) {
	m.userPermissionField = val
}

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

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

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

func unmarshalWebsite(data []byte, consumer runtime.Consumer) (Website, 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 "Website":
		var result website
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "pingcheck":
		var result PingCheck
		if err := consumer.Consume(buf2, &result); err != nil {
			return nil, err
		}
		return &result, nil
	case "webcheck":
		var result WebCheck
		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 website
func (m *website) Validate(formats strfmt.Registry) error {
	var res []error

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

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

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

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

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

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

func (m *website) validateCheckpoints(formats strfmt.Registry) error {
	if swag.IsZero(m.Checkpoints()) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *website) validateCollectors(formats strfmt.Registry) error {
	if swag.IsZero(m.Collectors()) { // not required
		return nil
	}

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

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

	}

	return nil
}

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

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

	return nil
}

func (m *website) validateProperties(formats strfmt.Registry) error {
	if swag.IsZero(m.Properties()) { // not required
		return nil
	}

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

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

	}

	return nil
}

func (m *website) validateTestLocation(formats strfmt.Registry) error {

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

	if m.TestLocation() != nil {
		if err := m.TestLocation().Validate(formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("testLocation")
			}
			return err
		}
	}

	return nil
}

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

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

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

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

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

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

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

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

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

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

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

func (m *website) contextValidateCheckpoints(ctx context.Context, formats strfmt.Registry) error {

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

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

	}

	return nil
}

func (m *website) contextValidateCollectors(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "collectors", "body", []*WebsiteCollectorInfo(m.Collectors())); err != nil {
		return err
	}

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

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

	}

	return nil
}

func (m *website) contextValidateGroupID(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *website) 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 *website) contextValidateLastUpdated(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *website) contextValidateProperties(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "properties", "body", []*NameAndValue(m.Properties())); err != nil {
		return err
	}

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

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

	}

	return nil
}

func (m *website) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {

	if err := validate.ReadOnly(ctx, "status", "body", string(m.Status())); err != nil {
		return err
	}

	return nil
}

func (m *website) contextValidateStopMonitoringByFolder(ctx context.Context, formats strfmt.Registry) error {

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

	return nil
}

func (m *website) contextValidateTestLocation(ctx context.Context, formats strfmt.Registry) error {

	if m.TestLocation() != nil {
		if err := m.TestLocation().ContextValidate(ctx, formats); err != nil {
			if ve, ok := err.(*errors.Validation); ok {
				return ve.ValidateName("testLocation")
			}
			return err
		}
	}

	return nil
}
