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

import (
	"context"
	"github.com/Azure/azure-service-operator/v2/internal/genericarmclient"
	"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/go-logr/logr"
	"github.com/rotisserie/eris"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime/schema"
	"sigs.k8s.io/controller-runtime/pkg/client"
)

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

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,network}
// +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 v1api20220401.TrafficManagerProfile
// Generator information:
// - Generated from: /trafficmanager/resource-manager/Microsoft.Network/stable/2022-04-01/trafficmanager.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}
type TrafficManagerProfile struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              TrafficManagerProfile_Spec   `json:"spec,omitempty"`
	Status            TrafficManagerProfile_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &TrafficManagerProfile{}

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

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

var _ configmaps.Exporter = &TrafficManagerProfile{}

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

var _ secrets.Exporter = &TrafficManagerProfile{}

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

var _ genruntime.KubernetesConfigExporter = &TrafficManagerProfile{}

// ExportKubernetesConfigMaps defines a resource which can create ConfigMaps in Kubernetes.
func (profile *TrafficManagerProfile) ExportKubernetesConfigMaps(_ context.Context, _ genruntime.MetaObject, _ *genericarmclient.GenericClient, _ logr.Logger) ([]client.Object, error) {
	collector := configmaps.NewCollector(profile.Namespace)
	if profile.Spec.OperatorSpec != nil && profile.Spec.OperatorSpec.ConfigMaps != nil {
		if profile.Status.DnsConfig != nil {
			if profile.Status.DnsConfig.Fqdn != nil {
				collector.AddValue(profile.Spec.OperatorSpec.ConfigMaps.DnsConfigFqdn, *profile.Status.DnsConfig.Fqdn)
			}
		}
	}
	result, err := collector.Values()
	if err != nil {
		return nil, err
	}
	return configmaps.SliceToClientObjectSlice(result), nil
}

var _ genruntime.KubernetesResource = &TrafficManagerProfile{}

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

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

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.Network/trafficmanagerprofiles"
func (profile *TrafficManagerProfile) GetType() string {
	return "Microsoft.Network/trafficmanagerprofiles"
}

// NewEmptyStatus returns a new empty (blank) status
func (profile *TrafficManagerProfile) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &TrafficManagerProfile_STATUS{}
}

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

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

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

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

	profile.Status = st
	return nil
}

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

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

// +kubebuilder:object:root=true
// Storage version of v1api20220401.TrafficManagerProfile
// Generator information:
// - Generated from: /trafficmanager/resource-manager/Microsoft.Network/stable/2022-04-01/trafficmanager.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}
type TrafficManagerProfileList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []TrafficManagerProfile `json:"items"`
}

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

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

// Storage version of v1api20220401.TrafficManagerProfile_Spec
type TrafficManagerProfile_Spec struct {
	AllowedEndpointRecordTypes []string `json:"allowedEndpointRecordTypes,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"`
	DnsConfig       *DnsConfig                         `json:"dnsConfig,omitempty"`
	Location        *string                            `json:"location,omitempty"`
	MaxReturn       *int                               `json:"maxReturn,omitempty"`
	MonitorConfig   *MonitorConfig                     `json:"monitorConfig,omitempty"`
	OperatorSpec    *TrafficManagerProfileOperatorSpec `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"`
	ProfileStatus               *string                            `json:"profileStatus,omitempty"`
	PropertyBag                 genruntime.PropertyBag             `json:"$propertyBag,omitempty"`
	Tags                        map[string]string                  `json:"tags,omitempty"`
	TrafficRoutingMethod        *string                            `json:"trafficRoutingMethod,omitempty"`
	TrafficViewEnrollmentStatus *string                            `json:"trafficViewEnrollmentStatus,omitempty"`
	Type                        *string                            `json:"type,omitempty"`
}

var _ genruntime.ConvertibleSpec = &TrafficManagerProfile_Spec{}

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

	return source.ConvertSpecTo(profile)
}

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

	return destination.ConvertSpecFrom(profile)
}

// Storage version of v1api20220401.TrafficManagerProfile_STATUS
type TrafficManagerProfile_STATUS struct {
	AllowedEndpointRecordTypes  []string               `json:"allowedEndpointRecordTypes,omitempty"`
	Conditions                  []conditions.Condition `json:"conditions,omitempty"`
	DnsConfig                   *DnsConfig_STATUS      `json:"dnsConfig,omitempty"`
	Endpoints                   []Endpoint_STATUS      `json:"endpoints,omitempty"`
	Id                          *string                `json:"id,omitempty"`
	Location                    *string                `json:"location,omitempty"`
	MaxReturn                   *int                   `json:"maxReturn,omitempty"`
	MonitorConfig               *MonitorConfig_STATUS  `json:"monitorConfig,omitempty"`
	Name                        *string                `json:"name,omitempty"`
	ProfileStatus               *string                `json:"profileStatus,omitempty"`
	PropertyBag                 genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Tags                        map[string]string      `json:"tags,omitempty"`
	TrafficRoutingMethod        *string                `json:"trafficRoutingMethod,omitempty"`
	TrafficViewEnrollmentStatus *string                `json:"trafficViewEnrollmentStatus,omitempty"`
	Type                        *string                `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &TrafficManagerProfile_STATUS{}

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

	return source.ConvertStatusTo(profile)
}

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

	return destination.ConvertStatusFrom(profile)
}

// Storage version of v1api20220401.DnsConfig
// Class containing DNS settings in a Traffic Manager profile.
type DnsConfig struct {
	PropertyBag  genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	RelativeName *string                `json:"relativeName,omitempty"`
	Ttl          *int                   `json:"ttl,omitempty"`
}

// Storage version of v1api20220401.DnsConfig_STATUS
// Class containing DNS settings in a Traffic Manager profile.
type DnsConfig_STATUS struct {
	Fqdn         *string                `json:"fqdn,omitempty"`
	PropertyBag  genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	RelativeName *string                `json:"relativeName,omitempty"`
	Ttl          *int                   `json:"ttl,omitempty"`
}

// Storage version of v1api20220401.Endpoint_STATUS
// Class representing a Traffic Manager endpoint.
type Endpoint_STATUS struct {
	Id          *string                `json:"id,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220401.MonitorConfig
// Class containing endpoint monitoring settings in a Traffic Manager profile.
type MonitorConfig struct {
	CustomHeaders             []MonitorConfig_CustomHeaders            `json:"customHeaders,omitempty"`
	ExpectedStatusCodeRanges  []MonitorConfig_ExpectedStatusCodeRanges `json:"expectedStatusCodeRanges,omitempty"`
	IntervalInSeconds         *int                                     `json:"intervalInSeconds,omitempty"`
	Path                      *string                                  `json:"path,omitempty"`
	Port                      *int                                     `json:"port,omitempty"`
	ProfileMonitorStatus      *string                                  `json:"profileMonitorStatus,omitempty"`
	PropertyBag               genruntime.PropertyBag                   `json:"$propertyBag,omitempty"`
	Protocol                  *string                                  `json:"protocol,omitempty"`
	TimeoutInSeconds          *int                                     `json:"timeoutInSeconds,omitempty"`
	ToleratedNumberOfFailures *int                                     `json:"toleratedNumberOfFailures,omitempty"`
}

// Storage version of v1api20220401.MonitorConfig_STATUS
// Class containing endpoint monitoring settings in a Traffic Manager profile.
type MonitorConfig_STATUS struct {
	CustomHeaders             []MonitorConfig_CustomHeaders_STATUS            `json:"customHeaders,omitempty"`
	ExpectedStatusCodeRanges  []MonitorConfig_ExpectedStatusCodeRanges_STATUS `json:"expectedStatusCodeRanges,omitempty"`
	IntervalInSeconds         *int                                            `json:"intervalInSeconds,omitempty"`
	Path                      *string                                         `json:"path,omitempty"`
	Port                      *int                                            `json:"port,omitempty"`
	ProfileMonitorStatus      *string                                         `json:"profileMonitorStatus,omitempty"`
	PropertyBag               genruntime.PropertyBag                          `json:"$propertyBag,omitempty"`
	Protocol                  *string                                         `json:"protocol,omitempty"`
	TimeoutInSeconds          *int                                            `json:"timeoutInSeconds,omitempty"`
	ToleratedNumberOfFailures *int                                            `json:"toleratedNumberOfFailures,omitempty"`
}

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

// Storage version of v1api20220401.MonitorConfig_CustomHeaders
type MonitorConfig_CustomHeaders struct {
	Name        *string                `json:"name,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Value       *string                `json:"value,omitempty"`
}

// Storage version of v1api20220401.MonitorConfig_CustomHeaders_STATUS
type MonitorConfig_CustomHeaders_STATUS struct {
	Name        *string                `json:"name,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Value       *string                `json:"value,omitempty"`
}

// Storage version of v1api20220401.MonitorConfig_ExpectedStatusCodeRanges
type MonitorConfig_ExpectedStatusCodeRanges struct {
	Max         *int                   `json:"max,omitempty"`
	Min         *int                   `json:"min,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220401.MonitorConfig_ExpectedStatusCodeRanges_STATUS
type MonitorConfig_ExpectedStatusCodeRanges_STATUS struct {
	Max         *int                   `json:"max,omitempty"`
	Min         *int                   `json:"min,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20220401.TrafficManagerProfileOperatorConfigMaps
type TrafficManagerProfileOperatorConfigMaps struct {
	DnsConfigFqdn *genruntime.ConfigMapDestination `json:"dnsConfigFqdn,omitempty"`
	PropertyBag   genruntime.PropertyBag           `json:"$propertyBag,omitempty"`
}

func init() {
	SchemeBuilder.Register(&TrafficManagerProfile{}, &TrafficManagerProfileList{})
}
