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

import (
	"fmt"
	arm "github.com/Azure/azure-service-operator/v2/api/apimanagement/v1api20230501preview/arm"
	storage "github.com/Azure/azure-service-operator/v2/api/apimanagement/v1api20230501preview/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"
	"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,apimanagement}
// +kubebuilder:subresource:status
// +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"
// Generator information:
// - Generated from: /apimanagement/resource-manager/Microsoft.ApiManagement/preview/2023-05-01-preview/apimsubscriptions.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions/{sid}
type Subscription struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              Subscription_Spec   `json:"spec,omitempty"`
	Status            Subscription_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &Subscription{}

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

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

var _ conversion.Convertible = &Subscription{}

// ConvertFrom populates our Subscription from the provided hub Subscription
func (subscription *Subscription) ConvertFrom(hub conversion.Hub) error {
	// intermediate variable for conversion
	var source storage.Subscription

	err := source.ConvertFrom(hub)
	if err != nil {
		return eris.Wrap(err, "converting from hub to source")
	}

	err = subscription.AssignProperties_From_Subscription(&source)
	if err != nil {
		return eris.Wrap(err, "converting from source to subscription")
	}

	return nil
}

// ConvertTo populates the provided hub Subscription from our Subscription
func (subscription *Subscription) ConvertTo(hub conversion.Hub) error {
	// intermediate variable for conversion
	var destination storage.Subscription
	err := subscription.AssignProperties_To_Subscription(&destination)
	if err != nil {
		return eris.Wrap(err, "converting to destination from subscription")
	}
	err = destination.ConvertTo(hub)
	if err != nil {
		return eris.Wrap(err, "converting from destination to hub")
	}

	return nil
}

var _ configmaps.Exporter = &Subscription{}

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

var _ secrets.Exporter = &Subscription{}

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

var _ genruntime.KubernetesResource = &Subscription{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2023-05-01-preview"
func (subscription Subscription) GetAPIVersion() string {
	return "2023-05-01-preview"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.ApiManagement/service/subscriptions"
func (subscription *Subscription) GetType() string {
	return "Microsoft.ApiManagement/service/subscriptions"
}

// NewEmptyStatus returns a new empty (blank) status
func (subscription *Subscription) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &Subscription_STATUS{}
}

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

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

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

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

	subscription.Status = st
	return nil
}

// AssignProperties_From_Subscription populates our Subscription from the provided source Subscription
func (subscription *Subscription) AssignProperties_From_Subscription(source *storage.Subscription) error {

	// ObjectMeta
	subscription.ObjectMeta = *source.ObjectMeta.DeepCopy()

	// Spec
	var spec Subscription_Spec
	err := spec.AssignProperties_From_Subscription_Spec(&source.Spec)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_From_Subscription_Spec() to populate field Spec")
	}
	subscription.Spec = spec

	// Status
	var status Subscription_STATUS
	err = status.AssignProperties_From_Subscription_STATUS(&source.Status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_From_Subscription_STATUS() to populate field Status")
	}
	subscription.Status = status

	// No error
	return nil
}

// AssignProperties_To_Subscription populates the provided destination Subscription from our Subscription
func (subscription *Subscription) AssignProperties_To_Subscription(destination *storage.Subscription) error {

	// ObjectMeta
	destination.ObjectMeta = *subscription.ObjectMeta.DeepCopy()

	// Spec
	var spec storage.Subscription_Spec
	err := subscription.Spec.AssignProperties_To_Subscription_Spec(&spec)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_To_Subscription_Spec() to populate field Spec")
	}
	destination.Spec = spec

	// Status
	var status storage.Subscription_STATUS
	err = subscription.Status.AssignProperties_To_Subscription_STATUS(&status)
	if err != nil {
		return eris.Wrap(err, "calling AssignProperties_To_Subscription_STATUS() to populate field Status")
	}
	destination.Status = status

	// No error
	return nil
}

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

// +kubebuilder:object:root=true
// Generator information:
// - Generated from: /apimanagement/resource-manager/Microsoft.ApiManagement/preview/2023-05-01-preview/apimsubscriptions.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/subscriptions/{sid}
type SubscriptionList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Subscription `json:"items"`
}

type Subscription_Spec struct {
	// AllowTracing: Determines whether tracing can be enabled
	AllowTracing *bool `json:"allowTracing,omitempty"`

	// +kubebuilder:validation:MaxLength=256
	// +kubebuilder:validation:Pattern="^[^*#&+:<>?]+$"
	// 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"`

	// +kubebuilder:validation:Required
	// +kubebuilder:validation:MaxLength=100
	// +kubebuilder:validation:MinLength=1
	// DisplayName: Subscription name.
	DisplayName *string `json:"displayName,omitempty"`

	// OperatorSpec: The specification for configuring operator behavior. This field is interpreted by the operator and not
	// passed directly to Azure
	OperatorSpec *SubscriptionOperatorSpec `json:"operatorSpec,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 apimanagement.azure.com/Service resource
	Owner *genruntime.KnownResourceReference `group:"apimanagement.azure.com" json:"owner,omitempty" kind:"Service"`

	// OwnerReference: User (user id path) for whom subscription is being created in form /users/{userId}
	OwnerReference *genruntime.ResourceReference `armReference:"OwnerId" json:"ownerReference,omitempty"`

	// PrimaryKey: Primary subscription key. If not specified during request key will be generated automatically.
	PrimaryKey *genruntime.SecretReference `json:"primaryKey,omitempty"`

	// +kubebuilder:validation:Required
	// Scope: Scope like /products/{productId} or /apis or /apis/{apiId}.
	Scope *string `json:"scope,omitempty"`

	// SecondaryKey: Secondary subscription key. If not specified during request key will be generated automatically.
	SecondaryKey *genruntime.SecretReference `json:"secondaryKey,omitempty"`

	// State: Initial subscription state. If no value is specified, subscription is created with Submitted state. Possible
	// states are * active – the subscription is active, * suspended – the subscription is blocked, and the subscriber
	// cannot call any APIs of the product, * submitted – the subscription request has been made by the developer, but has
	// not yet been approved or rejected, * rejected – the subscription request has been denied by an administrator, *
	// cancelled – the subscription has been cancelled by the developer or administrator, * expired – the subscription
	// reached its expiration date and was deactivated.
	State *SubscriptionCreateParameterProperties_State `json:"state,omitempty"`
}

var _ genruntime.ARMTransformer = &Subscription_Spec{}

// ConvertToARM converts from a Kubernetes CRD object to an ARM object
func (subscription *Subscription_Spec) ConvertToARM(resolved genruntime.ConvertToARMResolvedDetails) (interface{}, error) {
	if subscription == nil {
		return nil, nil
	}
	result := &arm.Subscription_Spec{}

	// Set property "Name":
	result.Name = resolved.Name

	// Set property "Properties":
	if subscription.AllowTracing != nil ||
		subscription.DisplayName != nil ||
		subscription.OwnerReference != nil ||
		subscription.PrimaryKey != nil ||
		subscription.Scope != nil ||
		subscription.SecondaryKey != nil ||
		subscription.State != nil {
		result.Properties = &arm.SubscriptionCreateParameterProperties{}
	}
	if subscription.AllowTracing != nil {
		allowTracing := *subscription.AllowTracing
		result.Properties.AllowTracing = &allowTracing
	}
	if subscription.DisplayName != nil {
		displayName := *subscription.DisplayName
		result.Properties.DisplayName = &displayName
	}
	if subscription.OwnerReference != nil {
		ownerIdARMID, err := resolved.ResolvedReferences.Lookup(*subscription.OwnerReference)
		if err != nil {
			return nil, err
		}
		ownerId := ownerIdARMID
		result.Properties.OwnerId = &ownerId
	}
	if subscription.PrimaryKey != nil {
		primaryKeySecret, err := resolved.ResolvedSecrets.Lookup(*subscription.PrimaryKey)
		if err != nil {
			return nil, eris.Wrap(err, "looking up secret for property PrimaryKey")
		}
		primaryKey := primaryKeySecret
		result.Properties.PrimaryKey = &primaryKey
	}
	if subscription.Scope != nil {
		scope := *subscription.Scope
		result.Properties.Scope = &scope
	}
	if subscription.SecondaryKey != nil {
		secondaryKeySecret, err := resolved.ResolvedSecrets.Lookup(*subscription.SecondaryKey)
		if err != nil {
			return nil, eris.Wrap(err, "looking up secret for property SecondaryKey")
		}
		secondaryKey := secondaryKeySecret
		result.Properties.SecondaryKey = &secondaryKey
	}
	if subscription.State != nil {
		var temp string
		temp = string(*subscription.State)
		state := arm.SubscriptionCreateParameterProperties_State(temp)
		result.Properties.State = &state
	}
	return result, nil
}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (subscription *Subscription_Spec) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &arm.Subscription_Spec{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (subscription *Subscription_Spec) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(arm.Subscription_Spec)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Subscription_Spec, got %T", armInput)
	}

	// Set property "AllowTracing":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowTracing != nil {
			allowTracing := *typedInput.Properties.AllowTracing
			subscription.AllowTracing = &allowTracing
		}
	}

	// Set property "AzureName":
	subscription.SetAzureName(genruntime.ExtractKubernetesResourceNameFromARMName(typedInput.Name))

	// Set property "DisplayName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DisplayName != nil {
			displayName := *typedInput.Properties.DisplayName
			subscription.DisplayName = &displayName
		}
	}

	// no assignment for property "OperatorSpec"

	// Set property "Owner":
	subscription.Owner = &genruntime.KnownResourceReference{
		Name:  owner.Name,
		ARMID: owner.ARMID,
	}

	// no assignment for property "OwnerReference"

	// no assignment for property "PrimaryKey"

	// Set property "Scope":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Scope != nil {
			scope := *typedInput.Properties.Scope
			subscription.Scope = &scope
		}
	}

	// no assignment for property "SecondaryKey"

	// Set property "State":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.State != nil {
			var temp string
			temp = string(*typedInput.Properties.State)
			state := SubscriptionCreateParameterProperties_State(temp)
			subscription.State = &state
		}
	}

	// No error
	return nil
}

var _ genruntime.ConvertibleSpec = &Subscription_Spec{}

// ConvertSpecFrom populates our Subscription_Spec from the provided source
func (subscription *Subscription_Spec) ConvertSpecFrom(source genruntime.ConvertibleSpec) error {
	src, ok := source.(*storage.Subscription_Spec)
	if ok {
		// Populate our instance from source
		return subscription.AssignProperties_From_Subscription_Spec(src)
	}

	// Convert to an intermediate form
	src = &storage.Subscription_Spec{}
	err := src.ConvertSpecFrom(source)
	if err != nil {
		return eris.Wrap(err, "initial step of conversion in ConvertSpecFrom()")
	}

	// Update our instance from src
	err = subscription.AssignProperties_From_Subscription_Spec(src)
	if err != nil {
		return eris.Wrap(err, "final step of conversion in ConvertSpecFrom()")
	}

	return nil
}

// ConvertSpecTo populates the provided destination from our Subscription_Spec
func (subscription *Subscription_Spec) ConvertSpecTo(destination genruntime.ConvertibleSpec) error {
	dst, ok := destination.(*storage.Subscription_Spec)
	if ok {
		// Populate destination from our instance
		return subscription.AssignProperties_To_Subscription_Spec(dst)
	}

	// Convert to an intermediate form
	dst = &storage.Subscription_Spec{}
	err := subscription.AssignProperties_To_Subscription_Spec(dst)
	if err != nil {
		return eris.Wrap(err, "initial step of conversion in ConvertSpecTo()")
	}

	// Update dst from our instance
	err = dst.ConvertSpecTo(destination)
	if err != nil {
		return eris.Wrap(err, "final step of conversion in ConvertSpecTo()")
	}

	return nil
}

// AssignProperties_From_Subscription_Spec populates our Subscription_Spec from the provided source Subscription_Spec
func (subscription *Subscription_Spec) AssignProperties_From_Subscription_Spec(source *storage.Subscription_Spec) error {

	// AllowTracing
	if source.AllowTracing != nil {
		allowTracing := *source.AllowTracing
		subscription.AllowTracing = &allowTracing
	} else {
		subscription.AllowTracing = nil
	}

	// AzureName
	subscription.AzureName = source.AzureName

	// DisplayName
	subscription.DisplayName = genruntime.ClonePointerToString(source.DisplayName)

	// OperatorSpec
	if source.OperatorSpec != nil {
		var operatorSpec SubscriptionOperatorSpec
		err := operatorSpec.AssignProperties_From_SubscriptionOperatorSpec(source.OperatorSpec)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_SubscriptionOperatorSpec() to populate field OperatorSpec")
		}
		subscription.OperatorSpec = &operatorSpec
	} else {
		subscription.OperatorSpec = nil
	}

	// Owner
	if source.Owner != nil {
		owner := source.Owner.Copy()
		subscription.Owner = &owner
	} else {
		subscription.Owner = nil
	}

	// OwnerReference
	if source.OwnerReference != nil {
		ownerReference := source.OwnerReference.Copy()
		subscription.OwnerReference = &ownerReference
	} else {
		subscription.OwnerReference = nil
	}

	// PrimaryKey
	if source.PrimaryKey != nil {
		primaryKey := source.PrimaryKey.Copy()
		subscription.PrimaryKey = &primaryKey
	} else {
		subscription.PrimaryKey = nil
	}

	// Scope
	subscription.Scope = genruntime.ClonePointerToString(source.Scope)

	// SecondaryKey
	if source.SecondaryKey != nil {
		secondaryKey := source.SecondaryKey.Copy()
		subscription.SecondaryKey = &secondaryKey
	} else {
		subscription.SecondaryKey = nil
	}

	// State
	if source.State != nil {
		state := *source.State
		stateTemp := genruntime.ToEnum(state, subscriptionCreateParameterProperties_State_Values)
		subscription.State = &stateTemp
	} else {
		subscription.State = nil
	}

	// No error
	return nil
}

// AssignProperties_To_Subscription_Spec populates the provided destination Subscription_Spec from our Subscription_Spec
func (subscription *Subscription_Spec) AssignProperties_To_Subscription_Spec(destination *storage.Subscription_Spec) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// AllowTracing
	if subscription.AllowTracing != nil {
		allowTracing := *subscription.AllowTracing
		destination.AllowTracing = &allowTracing
	} else {
		destination.AllowTracing = nil
	}

	// AzureName
	destination.AzureName = subscription.AzureName

	// DisplayName
	destination.DisplayName = genruntime.ClonePointerToString(subscription.DisplayName)

	// OperatorSpec
	if subscription.OperatorSpec != nil {
		var operatorSpec storage.SubscriptionOperatorSpec
		err := subscription.OperatorSpec.AssignProperties_To_SubscriptionOperatorSpec(&operatorSpec)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_SubscriptionOperatorSpec() to populate field OperatorSpec")
		}
		destination.OperatorSpec = &operatorSpec
	} else {
		destination.OperatorSpec = nil
	}

	// OriginalVersion
	destination.OriginalVersion = subscription.OriginalVersion()

	// Owner
	if subscription.Owner != nil {
		owner := subscription.Owner.Copy()
		destination.Owner = &owner
	} else {
		destination.Owner = nil
	}

	// OwnerReference
	if subscription.OwnerReference != nil {
		ownerReference := subscription.OwnerReference.Copy()
		destination.OwnerReference = &ownerReference
	} else {
		destination.OwnerReference = nil
	}

	// PrimaryKey
	if subscription.PrimaryKey != nil {
		primaryKey := subscription.PrimaryKey.Copy()
		destination.PrimaryKey = &primaryKey
	} else {
		destination.PrimaryKey = nil
	}

	// Scope
	destination.Scope = genruntime.ClonePointerToString(subscription.Scope)

	// SecondaryKey
	if subscription.SecondaryKey != nil {
		secondaryKey := subscription.SecondaryKey.Copy()
		destination.SecondaryKey = &secondaryKey
	} else {
		destination.SecondaryKey = nil
	}

	// State
	if subscription.State != nil {
		state := string(*subscription.State)
		destination.State = &state
	} else {
		destination.State = nil
	}

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

	// No error
	return nil
}

// OriginalVersion returns the original API version used to create the resource.
func (subscription *Subscription_Spec) OriginalVersion() string {
	return GroupVersion.Version
}

// SetAzureName sets the Azure name of the resource
func (subscription *Subscription_Spec) SetAzureName(azureName string) {
	subscription.AzureName = azureName
}

type Subscription_STATUS struct {
	// AllowTracing: Determines whether tracing is enabled
	AllowTracing *bool `json:"allowTracing,omitempty"`

	// Conditions: The observed state of the resource
	Conditions []conditions.Condition `json:"conditions,omitempty"`

	// CreatedDate: Subscription creation date. The date conforms to the following format: `yyyy-MM-ddTHH:mm:ssZ` as specified
	// by the ISO 8601 standard.
	CreatedDate *string `json:"createdDate,omitempty"`

	// DisplayName: The name of the subscription, or null if the subscription has no name.
	DisplayName *string `json:"displayName,omitempty"`

	// EndDate: Date when subscription was cancelled or expired. The setting is for audit purposes only and the subscription is
	// not automatically cancelled. The subscription lifecycle can be managed by using the `state` property. The date conforms
	// to the following format: `yyyy-MM-ddTHH:mm:ssZ` as specified by the ISO 8601 standard.
	EndDate *string `json:"endDate,omitempty"`

	// ExpirationDate: Subscription expiration date. The setting is for audit purposes only and the subscription is not
	// automatically expired. The subscription lifecycle can be managed by using the `state` property. The date conforms to the
	// following format: `yyyy-MM-ddTHH:mm:ssZ` as specified by the ISO 8601 standard.
	ExpirationDate *string `json:"expirationDate,omitempty"`

	// Id: Fully qualified resource ID for the resource. Ex -
	// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}
	Id *string `json:"id,omitempty"`

	// Name: The name of the resource
	Name *string `json:"name,omitempty"`

	// NotificationDate: Upcoming subscription expiration notification date. The date conforms to the following format:
	// `yyyy-MM-ddTHH:mm:ssZ` as specified by the ISO 8601 standard.
	NotificationDate *string `json:"notificationDate,omitempty"`

	// OwnerId: The user resource identifier of the subscription owner. The value is a valid relative URL in the format of
	// /users/{userId} where {userId} is a user identifier.
	OwnerId *string `json:"ownerId,omitempty"`

	// Scope: Scope like /products/{productId} or /apis or /apis/{apiId}.
	Scope *string `json:"scope,omitempty"`

	// StartDate: Subscription activation date. The setting is for audit purposes only and the subscription is not
	// automatically activated. The subscription lifecycle can be managed by using the `state` property. The date conforms to
	// the following format: `yyyy-MM-ddTHH:mm:ssZ` as specified by the ISO 8601 standard.
	StartDate *string `json:"startDate,omitempty"`

	// State: Subscription state. Possible states are * active – the subscription is active, * suspended – the subscription
	// is blocked, and the subscriber cannot call any APIs of the product, * submitted – the subscription request has been
	// made by the developer, but has not yet been approved or rejected, * rejected – the subscription request has been
	// denied by an administrator, * cancelled – the subscription has been cancelled by the developer or administrator, *
	// expired – the subscription reached its expiration date and was deactivated.
	State *SubscriptionContractProperties_State_STATUS `json:"state,omitempty"`

	// StateComment: Optional subscription comment added by an administrator when the state is changed to the 'rejected'.
	StateComment *string `json:"stateComment,omitempty"`

	// Type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts"
	Type *string `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &Subscription_STATUS{}

// ConvertStatusFrom populates our Subscription_STATUS from the provided source
func (subscription *Subscription_STATUS) ConvertStatusFrom(source genruntime.ConvertibleStatus) error {
	src, ok := source.(*storage.Subscription_STATUS)
	if ok {
		// Populate our instance from source
		return subscription.AssignProperties_From_Subscription_STATUS(src)
	}

	// Convert to an intermediate form
	src = &storage.Subscription_STATUS{}
	err := src.ConvertStatusFrom(source)
	if err != nil {
		return eris.Wrap(err, "initial step of conversion in ConvertStatusFrom()")
	}

	// Update our instance from src
	err = subscription.AssignProperties_From_Subscription_STATUS(src)
	if err != nil {
		return eris.Wrap(err, "final step of conversion in ConvertStatusFrom()")
	}

	return nil
}

// ConvertStatusTo populates the provided destination from our Subscription_STATUS
func (subscription *Subscription_STATUS) ConvertStatusTo(destination genruntime.ConvertibleStatus) error {
	dst, ok := destination.(*storage.Subscription_STATUS)
	if ok {
		// Populate destination from our instance
		return subscription.AssignProperties_To_Subscription_STATUS(dst)
	}

	// Convert to an intermediate form
	dst = &storage.Subscription_STATUS{}
	err := subscription.AssignProperties_To_Subscription_STATUS(dst)
	if err != nil {
		return eris.Wrap(err, "initial step of conversion in ConvertStatusTo()")
	}

	// Update dst from our instance
	err = dst.ConvertStatusTo(destination)
	if err != nil {
		return eris.Wrap(err, "final step of conversion in ConvertStatusTo()")
	}

	return nil
}

var _ genruntime.FromARMConverter = &Subscription_STATUS{}

// NewEmptyARMValue returns an empty ARM value suitable for deserializing into
func (subscription *Subscription_STATUS) NewEmptyARMValue() genruntime.ARMResourceStatus {
	return &arm.Subscription_STATUS{}
}

// PopulateFromARM populates a Kubernetes CRD object from an Azure ARM object
func (subscription *Subscription_STATUS) PopulateFromARM(owner genruntime.ArbitraryOwnerReference, armInput interface{}) error {
	typedInput, ok := armInput.(arm.Subscription_STATUS)
	if !ok {
		return fmt.Errorf("unexpected type supplied for PopulateFromARM() function. Expected arm.Subscription_STATUS, got %T", armInput)
	}

	// Set property "AllowTracing":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.AllowTracing != nil {
			allowTracing := *typedInput.Properties.AllowTracing
			subscription.AllowTracing = &allowTracing
		}
	}

	// no assignment for property "Conditions"

	// Set property "CreatedDate":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.CreatedDate != nil {
			createdDate := *typedInput.Properties.CreatedDate
			subscription.CreatedDate = &createdDate
		}
	}

	// Set property "DisplayName":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.DisplayName != nil {
			displayName := *typedInput.Properties.DisplayName
			subscription.DisplayName = &displayName
		}
	}

	// Set property "EndDate":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.EndDate != nil {
			endDate := *typedInput.Properties.EndDate
			subscription.EndDate = &endDate
		}
	}

	// Set property "ExpirationDate":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.ExpirationDate != nil {
			expirationDate := *typedInput.Properties.ExpirationDate
			subscription.ExpirationDate = &expirationDate
		}
	}

	// Set property "Id":
	if typedInput.Id != nil {
		id := *typedInput.Id
		subscription.Id = &id
	}

	// Set property "Name":
	if typedInput.Name != nil {
		name := *typedInput.Name
		subscription.Name = &name
	}

	// Set property "NotificationDate":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.NotificationDate != nil {
			notificationDate := *typedInput.Properties.NotificationDate
			subscription.NotificationDate = &notificationDate
		}
	}

	// Set property "OwnerId":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.OwnerId != nil {
			ownerId := *typedInput.Properties.OwnerId
			subscription.OwnerId = &ownerId
		}
	}

	// Set property "Scope":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.Scope != nil {
			scope := *typedInput.Properties.Scope
			subscription.Scope = &scope
		}
	}

	// Set property "StartDate":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.StartDate != nil {
			startDate := *typedInput.Properties.StartDate
			subscription.StartDate = &startDate
		}
	}

	// Set property "State":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.State != nil {
			var temp string
			temp = string(*typedInput.Properties.State)
			state := SubscriptionContractProperties_State_STATUS(temp)
			subscription.State = &state
		}
	}

	// Set property "StateComment":
	// copying flattened property:
	if typedInput.Properties != nil {
		if typedInput.Properties.StateComment != nil {
			stateComment := *typedInput.Properties.StateComment
			subscription.StateComment = &stateComment
		}
	}

	// Set property "Type":
	if typedInput.Type != nil {
		typeVar := *typedInput.Type
		subscription.Type = &typeVar
	}

	// No error
	return nil
}

// AssignProperties_From_Subscription_STATUS populates our Subscription_STATUS from the provided source Subscription_STATUS
func (subscription *Subscription_STATUS) AssignProperties_From_Subscription_STATUS(source *storage.Subscription_STATUS) error {

	// AllowTracing
	if source.AllowTracing != nil {
		allowTracing := *source.AllowTracing
		subscription.AllowTracing = &allowTracing
	} else {
		subscription.AllowTracing = nil
	}

	// Conditions
	subscription.Conditions = genruntime.CloneSliceOfCondition(source.Conditions)

	// CreatedDate
	subscription.CreatedDate = genruntime.ClonePointerToString(source.CreatedDate)

	// DisplayName
	subscription.DisplayName = genruntime.ClonePointerToString(source.DisplayName)

	// EndDate
	subscription.EndDate = genruntime.ClonePointerToString(source.EndDate)

	// ExpirationDate
	subscription.ExpirationDate = genruntime.ClonePointerToString(source.ExpirationDate)

	// Id
	subscription.Id = genruntime.ClonePointerToString(source.Id)

	// Name
	subscription.Name = genruntime.ClonePointerToString(source.Name)

	// NotificationDate
	subscription.NotificationDate = genruntime.ClonePointerToString(source.NotificationDate)

	// OwnerId
	subscription.OwnerId = genruntime.ClonePointerToString(source.OwnerId)

	// Scope
	subscription.Scope = genruntime.ClonePointerToString(source.Scope)

	// StartDate
	subscription.StartDate = genruntime.ClonePointerToString(source.StartDate)

	// State
	if source.State != nil {
		state := *source.State
		stateTemp := genruntime.ToEnum(state, subscriptionContractProperties_State_STATUS_Values)
		subscription.State = &stateTemp
	} else {
		subscription.State = nil
	}

	// StateComment
	subscription.StateComment = genruntime.ClonePointerToString(source.StateComment)

	// Type
	subscription.Type = genruntime.ClonePointerToString(source.Type)

	// No error
	return nil
}

// AssignProperties_To_Subscription_STATUS populates the provided destination Subscription_STATUS from our Subscription_STATUS
func (subscription *Subscription_STATUS) AssignProperties_To_Subscription_STATUS(destination *storage.Subscription_STATUS) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// AllowTracing
	if subscription.AllowTracing != nil {
		allowTracing := *subscription.AllowTracing
		destination.AllowTracing = &allowTracing
	} else {
		destination.AllowTracing = nil
	}

	// Conditions
	destination.Conditions = genruntime.CloneSliceOfCondition(subscription.Conditions)

	// CreatedDate
	destination.CreatedDate = genruntime.ClonePointerToString(subscription.CreatedDate)

	// DisplayName
	destination.DisplayName = genruntime.ClonePointerToString(subscription.DisplayName)

	// EndDate
	destination.EndDate = genruntime.ClonePointerToString(subscription.EndDate)

	// ExpirationDate
	destination.ExpirationDate = genruntime.ClonePointerToString(subscription.ExpirationDate)

	// Id
	destination.Id = genruntime.ClonePointerToString(subscription.Id)

	// Name
	destination.Name = genruntime.ClonePointerToString(subscription.Name)

	// NotificationDate
	destination.NotificationDate = genruntime.ClonePointerToString(subscription.NotificationDate)

	// OwnerId
	destination.OwnerId = genruntime.ClonePointerToString(subscription.OwnerId)

	// Scope
	destination.Scope = genruntime.ClonePointerToString(subscription.Scope)

	// StartDate
	destination.StartDate = genruntime.ClonePointerToString(subscription.StartDate)

	// State
	if subscription.State != nil {
		state := string(*subscription.State)
		destination.State = &state
	} else {
		destination.State = nil
	}

	// StateComment
	destination.StateComment = genruntime.ClonePointerToString(subscription.StateComment)

	// Type
	destination.Type = genruntime.ClonePointerToString(subscription.Type)

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

	// No error
	return nil
}

type SubscriptionContractProperties_State_STATUS string

const (
	SubscriptionContractProperties_State_STATUS_Active    = SubscriptionContractProperties_State_STATUS("active")
	SubscriptionContractProperties_State_STATUS_Cancelled = SubscriptionContractProperties_State_STATUS("cancelled")
	SubscriptionContractProperties_State_STATUS_Expired   = SubscriptionContractProperties_State_STATUS("expired")
	SubscriptionContractProperties_State_STATUS_Rejected  = SubscriptionContractProperties_State_STATUS("rejected")
	SubscriptionContractProperties_State_STATUS_Submitted = SubscriptionContractProperties_State_STATUS("submitted")
	SubscriptionContractProperties_State_STATUS_Suspended = SubscriptionContractProperties_State_STATUS("suspended")
)

// Mapping from string to SubscriptionContractProperties_State_STATUS
var subscriptionContractProperties_State_STATUS_Values = map[string]SubscriptionContractProperties_State_STATUS{
	"active":    SubscriptionContractProperties_State_STATUS_Active,
	"cancelled": SubscriptionContractProperties_State_STATUS_Cancelled,
	"expired":   SubscriptionContractProperties_State_STATUS_Expired,
	"rejected":  SubscriptionContractProperties_State_STATUS_Rejected,
	"submitted": SubscriptionContractProperties_State_STATUS_Submitted,
	"suspended": SubscriptionContractProperties_State_STATUS_Suspended,
}

// +kubebuilder:validation:Enum={"active","cancelled","expired","rejected","submitted","suspended"}
type SubscriptionCreateParameterProperties_State string

const (
	SubscriptionCreateParameterProperties_State_Active    = SubscriptionCreateParameterProperties_State("active")
	SubscriptionCreateParameterProperties_State_Cancelled = SubscriptionCreateParameterProperties_State("cancelled")
	SubscriptionCreateParameterProperties_State_Expired   = SubscriptionCreateParameterProperties_State("expired")
	SubscriptionCreateParameterProperties_State_Rejected  = SubscriptionCreateParameterProperties_State("rejected")
	SubscriptionCreateParameterProperties_State_Submitted = SubscriptionCreateParameterProperties_State("submitted")
	SubscriptionCreateParameterProperties_State_Suspended = SubscriptionCreateParameterProperties_State("suspended")
)

// Mapping from string to SubscriptionCreateParameterProperties_State
var subscriptionCreateParameterProperties_State_Values = map[string]SubscriptionCreateParameterProperties_State{
	"active":    SubscriptionCreateParameterProperties_State_Active,
	"cancelled": SubscriptionCreateParameterProperties_State_Cancelled,
	"expired":   SubscriptionCreateParameterProperties_State_Expired,
	"rejected":  SubscriptionCreateParameterProperties_State_Rejected,
	"submitted": SubscriptionCreateParameterProperties_State_Submitted,
	"suspended": SubscriptionCreateParameterProperties_State_Suspended,
}

// Details for configuring operator behavior. Fields in this struct are interpreted by the operator directly rather than being passed to Azure
type SubscriptionOperatorSpec struct {
	// ConfigMapExpressions: configures where to place operator written dynamic ConfigMaps (created with CEL expressions).
	ConfigMapExpressions []*core.DestinationExpression `json:"configMapExpressions,omitempty"`

	// SecretExpressions: configures where to place operator written dynamic secrets (created with CEL expressions).
	SecretExpressions []*core.DestinationExpression `json:"secretExpressions,omitempty"`

	// Secrets: configures where to place Azure generated secrets.
	Secrets *SubscriptionOperatorSecrets `json:"secrets,omitempty"`
}

// AssignProperties_From_SubscriptionOperatorSpec populates our SubscriptionOperatorSpec from the provided source SubscriptionOperatorSpec
func (operator *SubscriptionOperatorSpec) AssignProperties_From_SubscriptionOperatorSpec(source *storage.SubscriptionOperatorSpec) error {

	// ConfigMapExpressions
	if source.ConfigMapExpressions != nil {
		configMapExpressionList := make([]*core.DestinationExpression, len(source.ConfigMapExpressions))
		for configMapExpressionIndex, configMapExpressionItem := range source.ConfigMapExpressions {
			if configMapExpressionItem != nil {
				configMapExpression := *configMapExpressionItem.DeepCopy()
				configMapExpressionList[configMapExpressionIndex] = &configMapExpression
			} else {
				configMapExpressionList[configMapExpressionIndex] = nil
			}
		}
		operator.ConfigMapExpressions = configMapExpressionList
	} else {
		operator.ConfigMapExpressions = nil
	}

	// SecretExpressions
	if source.SecretExpressions != nil {
		secretExpressionList := make([]*core.DestinationExpression, len(source.SecretExpressions))
		for secretExpressionIndex, secretExpressionItem := range source.SecretExpressions {
			if secretExpressionItem != nil {
				secretExpression := *secretExpressionItem.DeepCopy()
				secretExpressionList[secretExpressionIndex] = &secretExpression
			} else {
				secretExpressionList[secretExpressionIndex] = nil
			}
		}
		operator.SecretExpressions = secretExpressionList
	} else {
		operator.SecretExpressions = nil
	}

	// Secrets
	if source.Secrets != nil {
		var secret SubscriptionOperatorSecrets
		err := secret.AssignProperties_From_SubscriptionOperatorSecrets(source.Secrets)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_From_SubscriptionOperatorSecrets() to populate field Secrets")
		}
		operator.Secrets = &secret
	} else {
		operator.Secrets = nil
	}

	// No error
	return nil
}

// AssignProperties_To_SubscriptionOperatorSpec populates the provided destination SubscriptionOperatorSpec from our SubscriptionOperatorSpec
func (operator *SubscriptionOperatorSpec) AssignProperties_To_SubscriptionOperatorSpec(destination *storage.SubscriptionOperatorSpec) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// ConfigMapExpressions
	if operator.ConfigMapExpressions != nil {
		configMapExpressionList := make([]*core.DestinationExpression, len(operator.ConfigMapExpressions))
		for configMapExpressionIndex, configMapExpressionItem := range operator.ConfigMapExpressions {
			if configMapExpressionItem != nil {
				configMapExpression := *configMapExpressionItem.DeepCopy()
				configMapExpressionList[configMapExpressionIndex] = &configMapExpression
			} else {
				configMapExpressionList[configMapExpressionIndex] = nil
			}
		}
		destination.ConfigMapExpressions = configMapExpressionList
	} else {
		destination.ConfigMapExpressions = nil
	}

	// SecretExpressions
	if operator.SecretExpressions != nil {
		secretExpressionList := make([]*core.DestinationExpression, len(operator.SecretExpressions))
		for secretExpressionIndex, secretExpressionItem := range operator.SecretExpressions {
			if secretExpressionItem != nil {
				secretExpression := *secretExpressionItem.DeepCopy()
				secretExpressionList[secretExpressionIndex] = &secretExpression
			} else {
				secretExpressionList[secretExpressionIndex] = nil
			}
		}
		destination.SecretExpressions = secretExpressionList
	} else {
		destination.SecretExpressions = nil
	}

	// Secrets
	if operator.Secrets != nil {
		var secret storage.SubscriptionOperatorSecrets
		err := operator.Secrets.AssignProperties_To_SubscriptionOperatorSecrets(&secret)
		if err != nil {
			return eris.Wrap(err, "calling AssignProperties_To_SubscriptionOperatorSecrets() to populate field Secrets")
		}
		destination.Secrets = &secret
	} else {
		destination.Secrets = nil
	}

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

	// No error
	return nil
}

type SubscriptionOperatorSecrets struct {
	// PrimaryKey: indicates where the PrimaryKey secret should be placed. If omitted, the secret will not be retrieved from
	// Azure.
	PrimaryKey *genruntime.SecretDestination `json:"primaryKey,omitempty"`

	// SecondaryKey: indicates where the SecondaryKey secret should be placed. If omitted, the secret will not be retrieved
	// from Azure.
	SecondaryKey *genruntime.SecretDestination `json:"secondaryKey,omitempty"`
}

// AssignProperties_From_SubscriptionOperatorSecrets populates our SubscriptionOperatorSecrets from the provided source SubscriptionOperatorSecrets
func (secrets *SubscriptionOperatorSecrets) AssignProperties_From_SubscriptionOperatorSecrets(source *storage.SubscriptionOperatorSecrets) error {

	// PrimaryKey
	if source.PrimaryKey != nil {
		primaryKey := source.PrimaryKey.Copy()
		secrets.PrimaryKey = &primaryKey
	} else {
		secrets.PrimaryKey = nil
	}

	// SecondaryKey
	if source.SecondaryKey != nil {
		secondaryKey := source.SecondaryKey.Copy()
		secrets.SecondaryKey = &secondaryKey
	} else {
		secrets.SecondaryKey = nil
	}

	// No error
	return nil
}

// AssignProperties_To_SubscriptionOperatorSecrets populates the provided destination SubscriptionOperatorSecrets from our SubscriptionOperatorSecrets
func (secrets *SubscriptionOperatorSecrets) AssignProperties_To_SubscriptionOperatorSecrets(destination *storage.SubscriptionOperatorSecrets) error {
	// Create a new property bag
	propertyBag := genruntime.NewPropertyBag()

	// PrimaryKey
	if secrets.PrimaryKey != nil {
		primaryKey := secrets.PrimaryKey.Copy()
		destination.PrimaryKey = &primaryKey
	} else {
		destination.PrimaryKey = nil
	}

	// SecondaryKey
	if secrets.SecondaryKey != nil {
		secondaryKey := secrets.SecondaryKey.Copy()
		destination.SecondaryKey = &secondaryKey
	} else {
		destination.SecondaryKey = nil
	}

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

	// No error
	return nil
}

func init() {
	SchemeBuilder.Register(&Subscription{}, &SubscriptionList{})
}
