// Code generated by azure-service-operator-codegen. DO NOT EDIT.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package storage

import (
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/conditions"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/configmaps"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/core"
	"github.com/Azure/azure-service-operator/v2/pkg/genruntime/secrets"
	"github.com/rotisserie/eris"
	"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
)

// +kubebuilder:rbac:groups=alertsmanagement.azure.com,resources=smartdetectoralertrules,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=alertsmanagement.azure.com,resources={smartdetectoralertrules/status,smartdetectoralertrules/finalizers},verbs=get;update;patch

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,alertsmanagement}
// +kubebuilder:subresource:status
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="Severity",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].severity"
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message"
// Storage version of v1api20210401.SmartDetectorAlertRule
// Generator information:
// - Generated from: /alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-04-01/SmartDetectorAlertRulesApi.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules/{alertRuleName}
type SmartDetectorAlertRule struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              SmartDetectorAlertRule_Spec   `json:"spec,omitempty"`
	Status            SmartDetectorAlertRule_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &SmartDetectorAlertRule{}

// GetConditions returns the conditions of the resource
func (rule *SmartDetectorAlertRule) GetConditions() conditions.Conditions {
	return rule.Status.Conditions
}

// SetConditions sets the conditions on the resource status
func (rule *SmartDetectorAlertRule) SetConditions(conditions conditions.Conditions) {
	rule.Status.Conditions = conditions
}

var _ configmaps.Exporter = &SmartDetectorAlertRule{}

// ConfigMapDestinationExpressions returns the Spec.OperatorSpec.ConfigMapExpressions property
func (rule *SmartDetectorAlertRule) ConfigMapDestinationExpressions() []*core.DestinationExpression {
	if rule.Spec.OperatorSpec == nil {
		return nil
	}
	return rule.Spec.OperatorSpec.ConfigMapExpressions
}

var _ secrets.Exporter = &SmartDetectorAlertRule{}

// SecretDestinationExpressions returns the Spec.OperatorSpec.SecretExpressions property
func (rule *SmartDetectorAlertRule) SecretDestinationExpressions() []*core.DestinationExpression {
	if rule.Spec.OperatorSpec == nil {
		return nil
	}
	return rule.Spec.OperatorSpec.SecretExpressions
}

var _ genruntime.KubernetesResource = &SmartDetectorAlertRule{}

// AzureName returns the Azure name of the resource
func (rule *SmartDetectorAlertRule) AzureName() string {
	return rule.Spec.AzureName
}

// GetAPIVersion returns the ARM API version of the resource. This is always "2021-04-01"
func (rule SmartDetectorAlertRule) GetAPIVersion() string {
	return "2021-04-01"
}

// GetResourceScope returns the scope of the resource
func (rule *SmartDetectorAlertRule) GetResourceScope() genruntime.ResourceScope {
	return genruntime.ResourceScopeResourceGroup
}

// GetSpec returns the specification of this resource
func (rule *SmartDetectorAlertRule) GetSpec() genruntime.ConvertibleSpec {
	return &rule.Spec
}

// GetStatus returns the status of this resource
func (rule *SmartDetectorAlertRule) GetStatus() genruntime.ConvertibleStatus {
	return &rule.Status
}

// GetSupportedOperations returns the operations supported by the resource
func (rule *SmartDetectorAlertRule) GetSupportedOperations() []genruntime.ResourceOperation {
	return []genruntime.ResourceOperation{
		genruntime.ResourceOperationDelete,
		genruntime.ResourceOperationGet,
		genruntime.ResourceOperationPut,
	}
}

// GetType returns the ARM Type of the resource. This is always "microsoft.alertsManagement/smartDetectorAlertRules"
func (rule *SmartDetectorAlertRule) GetType() string {
	return "microsoft.alertsManagement/smartDetectorAlertRules"
}

// NewEmptyStatus returns a new empty (blank) status
func (rule *SmartDetectorAlertRule) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &SmartDetectorAlertRule_STATUS{}
}

// Owner returns the ResourceReference of the owner
func (rule *SmartDetectorAlertRule) Owner() *genruntime.ResourceReference {
	if rule.Spec.Owner == nil {
		return nil
	}

	group, kind := genruntime.LookupOwnerGroupKind(rule.Spec)
	return rule.Spec.Owner.AsResourceReference(group, kind)
}

// SetStatus sets the status of this resource
func (rule *SmartDetectorAlertRule) SetStatus(status genruntime.ConvertibleStatus) error {
	// If we have exactly the right type of status, assign it
	if st, ok := status.(*SmartDetectorAlertRule_STATUS); ok {
		rule.Status = *st
		return nil
	}

	// Convert status to required version
	var st SmartDetectorAlertRule_STATUS
	err := status.ConvertStatusTo(&st)
	if err != nil {
		return eris.Wrap(err, "failed to convert status")
	}

	rule.Status = st
	return nil
}

// Hub marks that this SmartDetectorAlertRule is the hub type for conversion
func (rule *SmartDetectorAlertRule) Hub() {}

// OriginalGVK returns a GroupValueKind for the original API version used to create the resource
func (rule *SmartDetectorAlertRule) OriginalGVK() *schema.GroupVersionKind {
	return &schema.GroupVersionKind{
		Group:   GroupVersion.Group,
		Version: rule.Spec.OriginalVersion,
		Kind:    "SmartDetectorAlertRule",
	}
}

// +kubebuilder:object:root=true
// Storage version of v1api20210401.SmartDetectorAlertRule
// Generator information:
// - Generated from: /alertsmanagement/resource-manager/Microsoft.AlertsManagement/stable/2021-04-01/SmartDetectorAlertRulesApi.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/microsoft.alertsManagement/smartDetectorAlertRules/{alertRuleName}
type SmartDetectorAlertRuleList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []SmartDetectorAlertRule `json:"items"`
}

// Storage version of v1api20210401.APIVersion
// +kubebuilder:validation:Enum={"2021-04-01"}
type APIVersion string

const APIVersion_Value = APIVersion("2021-04-01")

// Storage version of v1api20210401.SmartDetectorAlertRule_Spec
type SmartDetectorAlertRule_Spec struct {
	ActionGroups *ActionGroupsInformation `json:"actionGroups,omitempty"`

	// AzureName: The name of the resource in Azure. This is often the same as the name of the resource in Kubernetes but it
	// doesn't have to be.
	AzureName       string                              `json:"azureName,omitempty"`
	Description     *string                             `json:"description,omitempty"`
	Detector        *Detector                           `json:"detector,omitempty"`
	Frequency       *string                             `json:"frequency,omitempty"`
	Location        *string                             `json:"location,omitempty"`
	OperatorSpec    *SmartDetectorAlertRuleOperatorSpec `json:"operatorSpec,omitempty"`
	OriginalVersion string                              `json:"originalVersion,omitempty"`

	// +kubebuilder:validation:Required
	// Owner: The owner of the resource. The owner controls where the resource goes when it is deployed. The owner also
	// controls the resources lifecycle. When the owner is deleted the resource will also be deleted. Owner is expected to be a
	// reference to a resources.azure.com/ResourceGroup resource
	Owner           *genruntime.KnownResourceReference `group:"resources.azure.com" json:"owner,omitempty" kind:"ResourceGroup"`
	PropertyBag     genruntime.PropertyBag             `json:"$propertyBag,omitempty"`
	ScopeReferences []genruntime.ResourceReference     `armReference:"Scope" json:"scopeReferences,omitempty"`
	Severity        *string                            `json:"severity,omitempty"`
	State           *string                            `json:"state,omitempty"`
	Tags            map[string]string                  `json:"tags,omitempty"`
	Throttling      *ThrottlingInformation             `json:"throttling,omitempty"`
}

var _ genruntime.ConvertibleSpec = &SmartDetectorAlertRule_Spec{}

// ConvertSpecFrom populates our SmartDetectorAlertRule_Spec from the provided source
func (rule *SmartDetectorAlertRule_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error {
	if source == rule {
		return eris.New("attempted conversion between unrelated implementations of github.com/Azure/azure-service-operator/v2/pkg/genruntime/ConvertibleSpec")
	}

	return source.ConvertSpecTo(rule)
}

// ConvertSpecTo populates the provided destination from our SmartDetectorAlertRule_Spec
func (rule *SmartDetectorAlertRule_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error {
	if destination == rule {
		return eris.New("attempted conversion between unrelated implementations of github.com/Azure/azure-service-operator/v2/pkg/genruntime/ConvertibleSpec")
	}

	return destination.ConvertSpecFrom(rule)
}

// Storage version of v1api20210401.SmartDetectorAlertRule_STATUS
type SmartDetectorAlertRule_STATUS struct {
	ActionGroups *ActionGroupsInformation_STATUS `json:"actionGroups,omitempty"`
	Conditions   []conditions.Condition          `json:"conditions,omitempty"`
	Description  *string                         `json:"description,omitempty"`
	Detector     *Detector_STATUS                `json:"detector,omitempty"`
	Frequency    *string                         `json:"frequency,omitempty"`
	Id           *string                         `json:"id,omitempty"`
	Location     *string                         `json:"location,omitempty"`
	Name         *string                         `json:"name,omitempty"`
	PropertyBag  genruntime.PropertyBag          `json:"$propertyBag,omitempty"`
	Scope        []string                        `json:"scope,omitempty"`
	Severity     *string                         `json:"severity,omitempty"`
	State        *string                         `json:"state,omitempty"`
	Tags         map[string]string               `json:"tags,omitempty"`
	Throttling   *ThrottlingInformation_STATUS   `json:"throttling,omitempty"`
	Type         *string                         `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &SmartDetectorAlertRule_STATUS{}

// ConvertStatusFrom populates our SmartDetectorAlertRule_STATUS from the provided source
func (rule *SmartDetectorAlertRule_STATUS) ConvertStatusFrom(source genruntime.ConvertibleStatus) error {
	if source == rule {
		return eris.New("attempted conversion between unrelated implementations of github.com/Azure/azure-service-operator/v2/pkg/genruntime/ConvertibleStatus")
	}

	return source.ConvertStatusTo(rule)
}

// ConvertStatusTo populates the provided destination from our SmartDetectorAlertRule_STATUS
func (rule *SmartDetectorAlertRule_STATUS) ConvertStatusTo(destination genruntime.ConvertibleStatus) error {
	if destination == rule {
		return eris.New("attempted conversion between unrelated implementations of github.com/Azure/azure-service-operator/v2/pkg/genruntime/ConvertibleStatus")
	}

	return destination.ConvertStatusFrom(rule)
}

// Storage version of v1api20210401.ActionGroupsInformation
// The Action Groups information, used by the alert rule.
type ActionGroupsInformation struct {
	CustomEmailSubject   *string                        `json:"customEmailSubject,omitempty"`
	CustomWebhookPayload *string                        `json:"customWebhookPayload,omitempty"`
	GroupReferences      []genruntime.ResourceReference `armReference:"GroupIds" json:"groupReferences,omitempty"`
	PropertyBag          genruntime.PropertyBag         `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20210401.ActionGroupsInformation_STATUS
// The Action Groups information, used by the alert rule.
type ActionGroupsInformation_STATUS struct {
	CustomEmailSubject   *string                `json:"customEmailSubject,omitempty"`
	CustomWebhookPayload *string                `json:"customWebhookPayload,omitempty"`
	GroupIds             []string               `json:"groupIds,omitempty"`
	PropertyBag          genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20210401.Detector
// The detector information. By default this is not populated, unless it's specified in expandDetector
type Detector struct {
	Id          *string                `json:"id,omitempty"`
	Parameters  map[string]v1.JSON     `json:"parameters,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20210401.Detector_STATUS
// The detector information. By default this is not populated, unless it's specified in expandDetector
type Detector_STATUS struct {
	Description            *string                              `json:"description,omitempty"`
	Id                     *string                              `json:"id,omitempty"`
	ImagePaths             []string                             `json:"imagePaths,omitempty"`
	Name                   *string                              `json:"name,omitempty"`
	ParameterDefinitions   []DetectorParameterDefinition_STATUS `json:"parameterDefinitions,omitempty"`
	Parameters             map[string]v1.JSON                   `json:"parameters,omitempty"`
	PropertyBag            genruntime.PropertyBag               `json:"$propertyBag,omitempty"`
	SupportedCadences      []int                                `json:"supportedCadences,omitempty"`
	SupportedResourceTypes []string                             `json:"supportedResourceTypes,omitempty"`
}

// Storage version of v1api20210401.SmartDetectorAlertRuleOperatorSpec
// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type SmartDetectorAlertRuleOperatorSpec struct {
	ConfigMapExpressions []*core.DestinationExpression `json:"configMapExpressions,omitempty"`
	PropertyBag          genruntime.PropertyBag        `json:"$propertyBag,omitempty"`
	SecretExpressions    []*core.DestinationExpression `json:"secretExpressions,omitempty"`
}

// Storage version of v1api20210401.ThrottlingInformation
// Optional throttling information for the alert rule.
type ThrottlingInformation struct {
	Duration    *string                `json:"duration,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20210401.ThrottlingInformation_STATUS
// Optional throttling information for the alert rule.
type ThrottlingInformation_STATUS struct {
	Duration    *string                `json:"duration,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20210401.DetectorParameterDefinition_STATUS
// The detector parameter definition.
type DetectorParameterDefinition_STATUS struct {
	Description *string                `json:"description,omitempty"`
	DisplayName *string                `json:"displayName,omitempty"`
	IsMandatory *bool                  `json:"isMandatory,omitempty"`
	Name        *string                `json:"name,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Type        *string                `json:"type,omitempty"`
}

func init() {
	SchemeBuilder.Register(&SmartDetectorAlertRule{}, &SmartDetectorAlertRuleList{})
}
