/// <summary>
        /// Determines whether the tenant has a storage blob configuration.
        /// </summary>
        /// <param name="tenant">The tenant.</param>
        /// <param name="definition">The blob storage container definition.</param>
        /// <returns>True if there is an explicit configuration set for this blob storage container definition.</returns>
        /// <remarks>This can be more efficient than trying to get the property, as it avoids a deserialization.</remarks>
        public static bool HasStorageBlobConfiguration(this ITenant tenant, BlobStorageContainerDefinition definition)
        {
            ArgumentNullException.ThrowIfNull(tenant);
            ArgumentNullException.ThrowIfNull(definition);

            return(tenant.Properties.TryGet <BlobStorageConfiguration>(GetConfigurationKey(definition), out BlobStorageConfiguration _));
        }
        /// <summary>
        /// Creates repository configuration properties suitable for passing to
        /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>.
        /// </summary>
        /// <param name="values">Existing configuration values to which to append these.</param>
        /// <param name="definition">The definition of the repository for which to set the configuration.</param>
        /// <param name="configuration">The configuration to set.</param>
        /// <returns>
        /// Properties to pass to
        /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>.
        /// </returns>
        public static IEnumerable <KeyValuePair <string, object> > AddBlobStorageConfiguration(
            this IEnumerable <KeyValuePair <string, object> > values,
            BlobStorageContainerDefinition definition,
            BlobStorageConfiguration configuration)
        {
            ArgumentNullException.ThrowIfNull(values);
            ArgumentNullException.ThrowIfNull(definition);
            ArgumentNullException.ThrowIfNull(configuration);

            return(values.Append(new KeyValuePair <string, object>(GetConfigurationKey(definition), configuration)));
        }
 private static string GetConfigurationKey(BlobStorageContainerDefinition definition)
 {
     return($"StorageConfiguration__{definition.ContainerName}");
 }
        /// <summary>
        /// Describes how to clear the repository configuration or the specified repository from tenant
        /// properties in form suitable for passing as the <c>propertiesToRemove</c> argument to
        /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>.
        /// </summary>
        /// <param name="definition">The definition of the repository for which to remove the configuration.</param>
        /// <returns>
        /// A single-entry list of properties that can be passed to
        /// <see cref="ITenantStore.UpdateTenantAsync(string, string?, IEnumerable{KeyValuePair{string, object}}?, IEnumerable{string}?)"/>
        /// to remove the storage configuration.
        /// </returns>
        public static IEnumerable <string> RemoveBlobStorageConfiguration(this BlobStorageContainerDefinition definition)
        {
            ArgumentNullException.ThrowIfNull(definition);

            return(new string[] { GetConfigurationKey(definition) });
        }
        /// <summary>
        /// Get the configuration for the specified blob container definition for a particular tenant.
        /// </summary>
        /// <param name="tenant">The tenant.</param>
        /// <param name="definition">The blob storage container definition.</param>
        /// <returns>The configuration for the storage account for this tenant.</returns>
        public static BlobStorageConfiguration GetBlobStorageConfiguration(this ITenant tenant, BlobStorageContainerDefinition definition)
        {
            ArgumentNullException.ThrowIfNull(tenant);
            ArgumentNullException.ThrowIfNull(definition);

            if (tenant.Properties.TryGet(GetConfigurationKey(definition), out BlobStorageConfiguration? configuration))
            {
                return(configuration);
            }

            throw new ArgumentException($"No Blob storage configuration was found for definition with container name '{definition.ContainerName}'");
        }