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

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

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

// +kubebuilder:object:root=true
// +kubebuilder:resource:categories={azure,documentdb}
// +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 v1api20240815.MongodbRoleDefinition
// Generator information:
// - Generated from: /cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2024-08-15/mongorbac.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/mongodbRoleDefinitions/{mongoRoleDefinitionId}
type MongodbRoleDefinition struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`
	Spec              MongodbRoleDefinition_Spec   `json:"spec,omitempty"`
	Status            MongodbRoleDefinition_STATUS `json:"status,omitempty"`
}

var _ conditions.Conditioner = &MongodbRoleDefinition{}

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

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

var _ configmaps.Exporter = &MongodbRoleDefinition{}

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

var _ secrets.Exporter = &MongodbRoleDefinition{}

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

var _ genruntime.KubernetesResource = &MongodbRoleDefinition{}

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

// GetAPIVersion returns the ARM API version of the resource. This is always "2024-08-15"
func (definition MongodbRoleDefinition) GetAPIVersion() string {
	return "2024-08-15"
}

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

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

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

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

// GetType returns the ARM Type of the resource. This is always "Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions"
func (definition *MongodbRoleDefinition) GetType() string {
	return "Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions"
}

// NewEmptyStatus returns a new empty (blank) status
func (definition *MongodbRoleDefinition) NewEmptyStatus() genruntime.ConvertibleStatus {
	return &MongodbRoleDefinition_STATUS{}
}

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

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

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

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

	definition.Status = st
	return nil
}

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

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

// +kubebuilder:object:root=true
// Storage version of v1api20240815.MongodbRoleDefinition
// Generator information:
// - Generated from: /cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2024-08-15/mongorbac.json
// - ARM URI: /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/mongodbRoleDefinitions/{mongoRoleDefinitionId}
type MongodbRoleDefinitionList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []MongodbRoleDefinition `json:"items"`
}

// Storage version of v1api20240815.MongodbRoleDefinition_Spec
type MongodbRoleDefinition_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"`
	DatabaseName    *string                            `json:"databaseName,omitempty"`
	OperatorSpec    *MongodbRoleDefinitionOperatorSpec `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 documentdb.azure.com/DatabaseAccount resource
	Owner       *genruntime.KnownResourceReference `group:"documentdb.azure.com" json:"owner,omitempty" kind:"DatabaseAccount"`
	Privileges  []Privilege                        `json:"privileges,omitempty"`
	PropertyBag genruntime.PropertyBag             `json:"$propertyBag,omitempty"`
	RoleName    *string                            `json:"roleName,omitempty"`
	Roles       []Role                             `json:"roles,omitempty"`
	Type        *string                            `json:"type,omitempty"`
}

var _ genruntime.ConvertibleSpec = &MongodbRoleDefinition_Spec{}

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

	return source.ConvertSpecTo(definition)
}

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

	return destination.ConvertSpecFrom(definition)
}

// Storage version of v1api20240815.MongodbRoleDefinition_STATUS
type MongodbRoleDefinition_STATUS struct {
	Conditions   []conditions.Condition `json:"conditions,omitempty"`
	DatabaseName *string                `json:"databaseName,omitempty"`
	Id           *string                `json:"id,omitempty"`
	Name         *string                `json:"name,omitempty"`
	Privileges   []Privilege_STATUS     `json:"privileges,omitempty"`
	PropertyBag  genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	RoleName     *string                `json:"roleName,omitempty"`
	Roles        []Role_STATUS          `json:"roles,omitempty"`
	Type         *string                `json:"type,omitempty"`
}

var _ genruntime.ConvertibleStatus = &MongodbRoleDefinition_STATUS{}

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

	return source.ConvertStatusTo(definition)
}

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

	return destination.ConvertStatusFrom(definition)
}

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

// Storage version of v1api20240815.Privilege
// The set of data plane operations permitted through this Role Definition.
type Privilege struct {
	Actions     []string               `json:"actions,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Resource    *Privilege_Resource    `json:"resource,omitempty"`
}

// Storage version of v1api20240815.Privilege_STATUS
// The set of data plane operations permitted through this Role Definition.
type Privilege_STATUS struct {
	Actions     []string                   `json:"actions,omitempty"`
	PropertyBag genruntime.PropertyBag     `json:"$propertyBag,omitempty"`
	Resource    *Privilege_Resource_STATUS `json:"resource,omitempty"`
}

// Storage version of v1api20240815.Role
// The set of roles permitted through this Role Definition.
type Role struct {
	Db          *string                `json:"db,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Role        *string                `json:"role,omitempty"`
}

// Storage version of v1api20240815.Role_STATUS
// The set of roles permitted through this Role Definition.
type Role_STATUS struct {
	Db          *string                `json:"db,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
	Role        *string                `json:"role,omitempty"`
}

// Storage version of v1api20240815.Privilege_Resource
type Privilege_Resource struct {
	Collection  *string                `json:"collection,omitempty"`
	Db          *string                `json:"db,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

// Storage version of v1api20240815.Privilege_Resource_STATUS
type Privilege_Resource_STATUS struct {
	Collection  *string                `json:"collection,omitempty"`
	Db          *string                `json:"db,omitempty"`
	PropertyBag genruntime.PropertyBag `json:"$propertyBag,omitempty"`
}

func init() {
	SchemeBuilder.Register(&MongodbRoleDefinition{}, &MongodbRoleDefinitionList{})
}
