// 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=notificationhubs.azure.com,resources=namespaces,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=notificationhubs.azure.com,resources={namespaces/status,namespaces/finalizers},verbs=get;update;patch

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,notificationhubs}
// +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 v1api20230901.Namespace
// Generator information:
// - Generated from: /notificationhubs/resource-manager/Microsoft.NotificationHubs/NotificationHubs/stable/2023-09-01/notificationhubs.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}
type Namespace struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              Namespace_Spec   `json:"spec,omitempty"`
	Status            Namespace_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &Namespace{}

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

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

var _ configmaps.Exporter = &Namespace{}

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

var _ secrets.Exporter = &Namespace{}

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

var _ genruntime.KubernetesConfigExporter = &Namespace{}

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

var _ genruntime.KubernetesResource = &Namespace{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2023-09-01"
func (namespace Namespace) GetAPIVersion() string {
	return "2023-09-01"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.NotificationHubs/namespaces"
func (namespace *Namespace) GetType() string {
	return "Microsoft.NotificationHubs/namespaces"
}

// NewEmptyStatus returns a new empty (blank) status
func (namespace *Namespace) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &Namespace_STATUS{}
}

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

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

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

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

	namespace.Status = st
	return nil
}

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

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

// +kubebuilder:object:root=true
// Storage version of v1api20230901.Namespace
// Generator information:
// - Generated from: /notificationhubs/resource-manager/Microsoft.NotificationHubs/NotificationHubs/stable/2023-09-01/notificationhubs.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NotificationHubs/namespaces/{namespaceName}
type NamespaceList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Namespace `json:"items"`
}

// Storage version of v1api20230901.APIVersion
// +kubebuilder:validation:Enum={"2023-09-01"}
type APIVersion string

const APIVersion_Value = APIVersion("2023-09-01")

// Storage version of v1api20230901.Namespace_Spec
type Namespace_Spec struct {
	// 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"`
	Location        *string                `json:"location,omitempty"`
	OperatorSpec    *NamespaceOperatorSpec `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"`
	Properties  *NamespaceProperties               `json:"properties,omitempty"`
	PropertyBag genruntime.PropertyBag             `json:"$propertyBag,omitempty"`
	Sku         *Sku                               `json:"sku,omitempty"`
	Tags        map[string]string                  `json:"tags,omitempty"`
}

var _ genruntime.ConvertibleSpec = &Namespace_Spec{}

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

	return source.ConvertSpecTo(namespace)
}

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

	return destination.ConvertSpecFrom(namespace)
}

// Storage version of v1api20230901.Namespace_STATUS
type Namespace_STATUS struct {
	Conditions  []conditions.Condition      `json:"conditions,omitempty"`
	Id          *string                     `json:"id,omitempty"`
	Location    *string                     `json:"location,omitempty"`
	Name        *string                     `json:"name,omitempty"`
	Properties  *NamespaceProperties_STATUS `json:"properties,omitempty"`
	PropertyBag genruntime.PropertyBag      `json:"$propertyBag,omitempty"`
	Sku         *Sku_STATUS                 `json:"sku,omitempty"`
	SystemData  *SystemData_STATUS          `json:"systemData,omitempty"`
	Tags        map[string]string           `json:"tags,omitempty"`
	Type        *string                     `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &Namespace_STATUS{}

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

	return source.ConvertStatusTo(namespace)
}

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

	return destination.ConvertStatusFrom(namespace)
}

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

// Storage version of v1api20230901.NamespaceProperties
// Represents namespace properties.
type NamespaceProperties struct {
	DataCenter          *string                `json:"dataCenter,omitempty"`
	NamespaceType       *string                `json:"namespaceType,omitempty"`
	NetworkAcls         *NetworkAcls           `json:"networkAcls,omitempty"`
	PnsCredentials      *PnsCredentials        `json:"pnsCredentials,omitempty"`
	PropertyBag         genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	PublicNetworkAccess *string                `json:"publicNetworkAccess,omitempty"`
	ReplicationRegion   *string                `json:"replicationRegion,omitempty"`
	ScaleUnit           *string                `json:"scaleUnit,omitempty"`
	ZoneRedundancy      *string                `json:"zoneRedundancy,omitempty"`
}

// Storage version of v1api20230901.NamespaceProperties_STATUS
// Represents namespace properties.
type NamespaceProperties_STATUS struct {
	CreatedAt                  *string                                    `json:"createdAt,omitempty"`
	Critical                   *bool                                      `json:"critical,omitempty"`
	DataCenter                 *string                                    `json:"dataCenter,omitempty"`
	Enabled                    *bool                                      `json:"enabled,omitempty"`
	MetricId                   *string                                    `json:"metricId,omitempty"`
	Name                       *string                                    `json:"name,omitempty"`
	NamespaceType              *string                                    `json:"namespaceType,omitempty"`
	NetworkAcls                *NetworkAcls_STATUS                        `json:"networkAcls,omitempty"`
	PnsCredentials             *PnsCredentials_STATUS                     `json:"pnsCredentials,omitempty"`
	PrivateEndpointConnections []PrivateEndpointConnectionResource_STATUS `json:"privateEndpointConnections,omitempty"`
	PropertyBag                genruntime.PropertyBag                     `json:"$propertyBag,omitempty"`
	ProvisioningState          *string                                    `json:"provisioningState,omitempty"`
	PublicNetworkAccess        *string                                    `json:"publicNetworkAccess,omitempty"`
	Region                     *string                                    `json:"region,omitempty"`
	ReplicationRegion          *string                                    `json:"replicationRegion,omitempty"`
	ScaleUnit                  *string                                    `json:"scaleUnit,omitempty"`
	ServiceBusEndpoint         *string                                    `json:"serviceBusEndpoint,omitempty"`
	Status                     *string                                    `json:"status,omitempty"`
	SubscriptionId             *string                                    `json:"subscriptionId,omitempty"`
	UpdatedAt                  *string                                    `json:"updatedAt,omitempty"`
	ZoneRedundancy             *string                                    `json:"zoneRedundancy,omitempty"`
}

// Storage version of v1api20230901.Sku
// The Sku description for a namespace
type Sku struct {
	Capacity    *int                   `json:"capacity,omitempty"`
	Family      *string                `json:"family,omitempty"`
	Name        *string                `json:"name,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Size        *string                `json:"size,omitempty"`
	Tier        *string                `json:"tier,omitempty"`
}

// Storage version of v1api20230901.Sku_STATUS
// The Sku description for a namespace
type Sku_STATUS struct {
	Capacity    *int                   `json:"capacity,omitempty"`
	Family      *string                `json:"family,omitempty"`
	Name        *string                `json:"name,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Size        *string                `json:"size,omitempty"`
	Tier        *string                `json:"tier,omitempty"`
}

// Storage version of v1api20230901.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"`
}

// Storage version of v1api20230901.NamespaceOperatorConfigMaps
type NamespaceOperatorConfigMaps struct {
	PropertyBag        genruntime.PropertyBag           `json:"$propertyBag,omitempty"`
	ServiceBusEndpoint *genruntime.ConfigMapDestination `json:"serviceBusEndpoint,omitempty"`
}

// Storage version of v1api20230901.NamespaceOperatorSecrets
type NamespaceOperatorSecrets struct {
	PrimaryConnectionString   *genruntime.SecretDestination `json:"primaryConnectionString,omitempty"`
	PrimaryKey                *genruntime.SecretDestination `json:"primaryKey,omitempty"`
	PropertyBag               genruntime.PropertyBag        `json:"$propertyBag,omitempty"`
	SecondaryConnectionString *genruntime.SecretDestination `json:"secondaryConnectionString,omitempty"`
	SecondaryKey              *genruntime.SecretDestination `json:"secondaryKey,omitempty"`
}

// Storage version of v1api20230901.NetworkAcls
// A collection of network authorization rules.
type NetworkAcls struct {
	IpRules           []IpRule                         `json:"ipRules,omitempty"`
	PropertyBag       genruntime.PropertyBag           `json:"$propertyBag,omitempty"`
	PublicNetworkRule *PublicInternetAuthorizationRule `json:"publicNetworkRule,omitempty"`
}

// Storage version of v1api20230901.NetworkAcls_STATUS
// A collection of network authorization rules.
type NetworkAcls_STATUS struct {
	IpRules           []IpRule_STATUS                         `json:"ipRules,omitempty"`
	PropertyBag       genruntime.PropertyBag                  `json:"$propertyBag,omitempty"`
	PublicNetworkRule *PublicInternetAuthorizationRule_STATUS `json:"publicNetworkRule,omitempty"`
}

// Storage version of v1api20230901.PnsCredentials
// Collection of Notification Hub or Notification Hub Namespace PNS credentials.
type PnsCredentials struct {
	AdmCredential     *AdmCredential         `json:"admCredential,omitempty"`
	ApnsCredential    *ApnsCredential        `json:"apnsCredential,omitempty"`
	BaiduCredential   *BaiduCredential       `json:"baiduCredential,omitempty"`
	BrowserCredential *BrowserCredential     `json:"browserCredential,omitempty"`
	GcmCredential     *GcmCredential         `json:"gcmCredential,omitempty"`
	MpnsCredential    *MpnsCredential        `json:"mpnsCredential,omitempty"`
	PropertyBag       genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	WnsCredential     *WnsCredential         `json:"wnsCredential,omitempty"`
	XiaomiCredential  *XiaomiCredential      `json:"xiaomiCredential,omitempty"`
}

// Storage version of v1api20230901.PnsCredentials_STATUS
// Collection of Notification Hub or Notification Hub Namespace PNS credentials.
type PnsCredentials_STATUS struct {
	AdmCredential     *AdmCredential_STATUS     `json:"admCredential,omitempty"`
	ApnsCredential    *ApnsCredential_STATUS    `json:"apnsCredential,omitempty"`
	BaiduCredential   *BaiduCredential_STATUS   `json:"baiduCredential,omitempty"`
	BrowserCredential *BrowserCredential_STATUS `json:"browserCredential,omitempty"`
	GcmCredential     *GcmCredential_STATUS     `json:"gcmCredential,omitempty"`
	MpnsCredential    *MpnsCredential_STATUS    `json:"mpnsCredential,omitempty"`
	PropertyBag       genruntime.PropertyBag    `json:"$propertyBag,omitempty"`
	WnsCredential     *WnsCredential_STATUS     `json:"wnsCredential,omitempty"`
	XiaomiCredential  *XiaomiCredential_STATUS  `json:"xiaomiCredential,omitempty"`
}

// Storage version of v1api20230901.PrivateEndpointConnectionResource_STATUS
// Represents a Private Endpoint Connection ARM resource - a sub-resource of Notification Hubs namespace.
type PrivateEndpointConnectionResource_STATUS struct {
	Id          *string                `json:"id,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20230901.IpRule
// A network authorization rule that filters traffic based on IP address.
type IpRule struct {
	IpMask      *string                `json:"ipMask,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Rights      []string               `json:"rights,omitempty"`
}

// Storage version of v1api20230901.IpRule_STATUS
// A network authorization rule that filters traffic based on IP address.
type IpRule_STATUS struct {
	IpMask      *string                `json:"ipMask,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Rights      []string               `json:"rights,omitempty"`
}

// Storage version of v1api20230901.PublicInternetAuthorizationRule
// A default (public Internet) network authorization rule, which contains rights if no other network rule matches.
type PublicInternetAuthorizationRule struct {
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Rights      []string               `json:"rights,omitempty"`
}

// Storage version of v1api20230901.PublicInternetAuthorizationRule_STATUS
// A default (public Internet) network authorization rule, which contains rights if no other network rule matches.
type PublicInternetAuthorizationRule_STATUS struct {
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Rights      []string               `json:"rights,omitempty"`
}

func init() {
	SchemeBuilder.Register(&Namespace{}, &NamespaceList{})
}
