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

import (
	storage "github.com/Azure/azure-service-operator/v2/api/insights/v1api20221001/storage"
	"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"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
)

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

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,insights}
// +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 v1api20220615.ScheduledQueryRule
// Generator information:
// - Generated from: /monitor/resource-manager/Microsoft.Insights/stable/2022-06-15/scheduledQueryRule_API.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/scheduledQueryRules/{ruleName}
type ScheduledQueryRule struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              ScheduledQueryRule_Spec   `json:"spec,omitempty"`
	Status            ScheduledQueryRule_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &ScheduledQueryRule{}

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

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

var _ configmaps.Exporter = &ScheduledQueryRule{}

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

var _ secrets.Exporter = &ScheduledQueryRule{}

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

var _ genruntime.KubernetesResource = &ScheduledQueryRule{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2022-06-15"
func (rule ScheduledQueryRule) GetAPIVersion() string {
	return "2022-06-15"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Insights/scheduledQueryRules"
func (rule *ScheduledQueryRule) GetType() string {
	return "Microsoft.Insights/scheduledQueryRules"
}

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

// Owner returns the ResourceReference of the owner
func (rule *ScheduledQueryRule) 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 *ScheduledQueryRule) SetStatus(status genruntime.ConvertibleStatus) error {
	// If we have exactly the right type of status, assign it
	if st, ok := status.(*ScheduledQueryRule_STATUS); ok {
		rule.Status = *st
		return nil
	}

	// Convert status to required version
	var st ScheduledQueryRule_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 ScheduledQueryRule is the hub type for conversion
func (rule *ScheduledQueryRule) Hub() {}

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

// +kubebuilder:object:root=true
// Storage version of v1api20220615.ScheduledQueryRule
// Generator information:
// - Generated from: /monitor/resource-manager/Microsoft.Insights/stable/2022-06-15/scheduledQueryRule_API.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Insights/scheduledQueryRules/{ruleName}
type ScheduledQueryRuleList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []ScheduledQueryRule `json:"items"`
}

// Storage version of v1api20220615.APIVersion
// +kubebuilder:validation:Enum={"2022-06-15"}
type APIVersion string

const APIVersion_Value = APIVersion("2022-06-15")

// Storage version of v1api20220615.ScheduledQueryRule_Spec
type ScheduledQueryRule_Spec struct {
	Actions      *Actions `json:"actions,omitempty"`
	AutoMitigate *bool    `json:"autoMitigate,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"`
	CheckWorkspaceAlertsStorageConfigured *bool                           `json:"checkWorkspaceAlertsStorageConfigured,omitempty"`
	Criteria                              *ScheduledQueryRuleCriteria     `json:"criteria,omitempty"`
	Description                           *string                         `json:"description,omitempty"`
	DisplayName                           *string                         `json:"displayName,omitempty"`
	Enabled                               *bool                           `json:"enabled,omitempty"`
	EvaluationFrequency                   *string                         `json:"evaluationFrequency,omitempty"`
	Kind                                  *string                         `json:"kind,omitempty"`
	Location                              *string                         `json:"location,omitempty"`
	MuteActionsDuration                   *string                         `json:"muteActionsDuration,omitempty"`
	OperatorSpec                          *ScheduledQueryRuleOperatorSpec `json:"operatorSpec,omitempty"`
	OriginalVersion                       string                          `json:"originalVersion,omitempty"`
	OverrideQueryTimeRange                *string                         `json:"overrideQueryTimeRange,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"`
	ScopesReferences    []genruntime.ResourceReference     `armReference:"Scopes" json:"scopesReferences,omitempty"`
	Severity            *int                               `json:"severity,omitempty"`
	SkipQueryValidation *bool                              `json:"skipQueryValidation,omitempty"`
	Tags                map[string]string                  `json:"tags,omitempty"`
	TargetResourceTypes []string                           `json:"targetResourceTypes,omitempty"`
	WindowSize          *string                            `json:"windowSize,omitempty"`
}

var _ genruntime.ConvertibleSpec = &ScheduledQueryRule_Spec{}

// ConvertSpecFrom populates our ScheduledQueryRule_Spec from the provided source
func (rule *ScheduledQueryRule_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 ScheduledQueryRule_Spec
func (rule *ScheduledQueryRule_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 v1api20220615.ScheduledQueryRule_STATUS
type ScheduledQueryRule_STATUS struct {
	Actions                               *Actions_STATUS                    `json:"actions,omitempty"`
	AutoMitigate                          *bool                              `json:"autoMitigate,omitempty"`
	CheckWorkspaceAlertsStorageConfigured *bool                              `json:"checkWorkspaceAlertsStorageConfigured,omitempty"`
	Conditions                            []conditions.Condition             `json:"conditions,omitempty"`
	CreatedWithApiVersion                 *string                            `json:"createdWithApiVersion,omitempty"`
	Criteria                              *ScheduledQueryRuleCriteria_STATUS `json:"criteria,omitempty"`
	Description                           *string                            `json:"description,omitempty"`
	DisplayName                           *string                            `json:"displayName,omitempty"`
	Enabled                               *bool                              `json:"enabled,omitempty"`
	Etag                                  *string                            `json:"etag,omitempty"`
	EvaluationFrequency                   *string                            `json:"evaluationFrequency,omitempty"`
	Id                                    *string                            `json:"id,omitempty"`
	IsLegacyLogAnalyticsRule              *bool                              `json:"isLegacyLogAnalyticsRule,omitempty"`
	IsWorkspaceAlertsStorageConfigured    *bool                              `json:"isWorkspaceAlertsStorageConfigured,omitempty"`
	Kind                                  *string                            `json:"kind,omitempty"`
	Location                              *string                            `json:"location,omitempty"`
	MuteActionsDuration                   *string                            `json:"muteActionsDuration,omitempty"`
	Name                                  *string                            `json:"name,omitempty"`
	OverrideQueryTimeRange                *string                            `json:"overrideQueryTimeRange,omitempty"`
	PropertyBag                           genruntime.PropertyBag             `json:"$propertyBag,omitempty"`
	Scopes                                []string                           `json:"scopes,omitempty"`
	Severity                              *int                               `json:"severity,omitempty"`
	SkipQueryValidation                   *bool                              `json:"skipQueryValidation,omitempty"`
	SystemData                            *SystemData_STATUS                 `json:"systemData,omitempty"`
	Tags                                  map[string]string                  `json:"tags,omitempty"`
	TargetResourceTypes                   []string                           `json:"targetResourceTypes,omitempty"`
	Type                                  *string                            `json:"type,omitempty"`
	WindowSize                            *string                            `json:"windowSize,omitempty"`
}

var _ genruntime.ConvertibleStatus = &ScheduledQueryRule_STATUS{}

// ConvertStatusFrom populates our ScheduledQueryRule_STATUS from the provided source
func (rule *ScheduledQueryRule_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 ScheduledQueryRule_STATUS
func (rule *ScheduledQueryRule_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 v1api20220615.Actions
// Actions to invoke when the alert fires.
type Actions struct {
	ActionGroupsReferences []genruntime.ResourceReference `armReference:"ActionGroups" json:"actionGroupsReferences,omitempty"`
	CustomProperties       map[string]string              `json:"customProperties,omitempty"`
	PropertyBag            genruntime.PropertyBag         `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220615.Actions_STATUS
// Actions to invoke when the alert fires.
type Actions_STATUS struct {
	ActionGroups     []string               `json:"actionGroups,omitempty"`
	CustomProperties map[string]string      `json:"customProperties,omitempty"`
	PropertyBag      genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220615.ScheduledQueryRuleCriteria
// The rule criteria that defines the conditions of the scheduled query rule.
type ScheduledQueryRuleCriteria struct {
	AllOf       []Condition            `json:"allOf,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220615.ScheduledQueryRuleCriteria_STATUS
// The rule criteria that defines the conditions of the scheduled query rule.
type ScheduledQueryRuleCriteria_STATUS struct {
	AllOf       []Condition_STATUS     `json:"allOf,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

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

// Storage version of v1api20220615.SystemData_STATUS
// Metadata pertaining to creation and last modification of the resource.
type SystemData_STATUS struct {
	CreatedAt          *string                `json:"createdAt,omitempty"`
	CreatedBy          *string                `json:"createdBy,omitempty"`
	CreatedByType      *string                `json:"createdByType,omitempty"`
	LastModifiedAt     *string                `json:"lastModifiedAt,omitempty"`
	LastModifiedBy     *string                `json:"lastModifiedBy,omitempty"`
	LastModifiedByType *string                `json:"lastModifiedByType,omitempty"`
	PropertyBag        genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// AssignProperties_From_SystemData_STATUS populates our SystemData_STATUS from the provided source SystemData_STATUS
func (data *SystemData_STATUS) AssignProperties_From_SystemData_STATUS(source *storage.SystemData_STATUS) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(source.PropertyBag)

	// CreatedAt
	data.CreatedAt = genruntime.ClonePointerToString(source.CreatedAt)

	// CreatedBy
	data.CreatedBy = genruntime.ClonePointerToString(source.CreatedBy)

	// CreatedByType
	data.CreatedByType = genruntime.ClonePointerToString(source.CreatedByType)

	// LastModifiedAt
	data.LastModifiedAt = genruntime.ClonePointerToString(source.LastModifiedAt)

	// LastModifiedBy
	data.LastModifiedBy = genruntime.ClonePointerToString(source.LastModifiedBy)

	// LastModifiedByType
	data.LastModifiedByType = genruntime.ClonePointerToString(source.LastModifiedByType)

	// Update the property bag
	if len(propertyBag) > 0 {
		data.PropertyBag = propertyBag
	} else {
		data.PropertyBag = nil
	}

	// Invoke the augmentConversionForSystemData_STATUS interface (if implemented) to customize the conversion
	var dataAsAny any = data
	if augmentedData, ok := dataAsAny.(augmentConversionForSystemData_STATUS); ok {
		err := augmentedData.AssignPropertiesFrom(source)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesFrom() for conversion")
		}
	}

	// No error
	return nil
}

// AssignProperties_To_SystemData_STATUS populates the provided destination SystemData_STATUS from our SystemData_STATUS
func (data *SystemData_STATUS) AssignProperties_To_SystemData_STATUS(destination *storage.SystemData_STATUS) error {
	// Clone the existing property bag
	propertyBag := genruntime.NewPropertyBag(data.PropertyBag)

	// CreatedAt
	destination.CreatedAt = genruntime.ClonePointerToString(data.CreatedAt)

	// CreatedBy
	destination.CreatedBy = genruntime.ClonePointerToString(data.CreatedBy)

	// CreatedByType
	destination.CreatedByType = genruntime.ClonePointerToString(data.CreatedByType)

	// LastModifiedAt
	destination.LastModifiedAt = genruntime.ClonePointerToString(data.LastModifiedAt)

	// LastModifiedBy
	destination.LastModifiedBy = genruntime.ClonePointerToString(data.LastModifiedBy)

	// LastModifiedByType
	destination.LastModifiedByType = genruntime.ClonePointerToString(data.LastModifiedByType)

	// Update the property bag
	if len(propertyBag) > 0 {
		destination.PropertyBag = propertyBag
	} else {
		destination.PropertyBag = nil
	}

	// Invoke the augmentConversionForSystemData_STATUS interface (if implemented) to customize the conversion
	var dataAsAny any = data
	if augmentedData, ok := dataAsAny.(augmentConversionForSystemData_STATUS); ok {
		err := augmentedData.AssignPropertiesTo(destination)
		if err != nil {
			return eris.Wrap(err, "calling augmented AssignPropertiesTo() for conversion")
		}
	}

	// No error
	return nil
}

type augmentConversionForSystemData_STATUS interface {
	AssignPropertiesFrom(src *storage.SystemData_STATUS) error
	AssignPropertiesTo(dst *storage.SystemData_STATUS) error
}

// Storage version of v1api20220615.Condition
// A condition of the scheduled query rule.
type Condition struct {
	Dimensions          []Dimension               `json:"dimensions,omitempty"`
	FailingPeriods      *Condition_FailingPeriods `json:"failingPeriods,omitempty"`
	MetricMeasureColumn *string                   `json:"metricMeasureColumn,omitempty"`
	MetricName          *string                   `json:"metricName,omitempty"`
	Operator            *string                   `json:"operator,omitempty"`
	PropertyBag         genruntime.PropertyBag    `json:"$propertyBag,omitempty"`
	Query               *string                   `json:"query,omitempty"`

	// ResourceIdColumnReference: The column containing the resource id. The content of the column must be a uri formatted as
	// resource id. Relevant only for rules of the kind LogAlert.
	ResourceIdColumnReference *genruntime.ResourceReference `armReference:"ResourceIdColumn" json:"resourceIdColumnReference,omitempty"`
	Threshold                 *float64                      `json:"threshold,omitempty"`
	TimeAggregation           *string                       `json:"timeAggregation,omitempty"`
}

// Storage version of v1api20220615.Condition_STATUS
// A condition of the scheduled query rule.
type Condition_STATUS struct {
	Dimensions          []Dimension_STATUS               `json:"dimensions,omitempty"`
	FailingPeriods      *Condition_FailingPeriods_STATUS `json:"failingPeriods,omitempty"`
	MetricMeasureColumn *string                          `json:"metricMeasureColumn,omitempty"`
	MetricName          *string                          `json:"metricName,omitempty"`
	Operator            *string                          `json:"operator,omitempty"`
	PropertyBag         genruntime.PropertyBag           `json:"$propertyBag,omitempty"`
	Query               *string                          `json:"query,omitempty"`
	ResourceIdColumn    *string                          `json:"resourceIdColumn,omitempty"`
	Threshold           *float64                         `json:"threshold,omitempty"`
	TimeAggregation     *string                          `json:"timeAggregation,omitempty"`
}

// Storage version of v1api20220615.Condition_FailingPeriods
type Condition_FailingPeriods struct {
	MinFailingPeriodsToAlert  *int                   `json:"minFailingPeriodsToAlert,omitempty"`
	NumberOfEvaluationPeriods *int                   `json:"numberOfEvaluationPeriods,omitempty"`
	PropertyBag               genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220615.Condition_FailingPeriods_STATUS
type Condition_FailingPeriods_STATUS struct {
	MinFailingPeriodsToAlert  *int                   `json:"minFailingPeriodsToAlert,omitempty"`
	NumberOfEvaluationPeriods *int                   `json:"numberOfEvaluationPeriods,omitempty"`
	PropertyBag               genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220615.Dimension
// Dimension splitting and filtering definition
type Dimension struct {
	Name        *string                `json:"name,omitempty"`
	Operator    *string                `json:"operator,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Values      []string               `json:"values,omitempty"`
}

// Storage version of v1api20220615.Dimension_STATUS
// Dimension splitting and filtering definition
type Dimension_STATUS struct {
	Name        *string                `json:"name,omitempty"`
	Operator    *string                `json:"operator,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Values      []string               `json:"values,omitempty"`
}

func init() {
	SchemeBuilder.Register(&ScheduledQueryRule{}, &ScheduledQueryRuleList{})
}
