private static LocationAttributeViewModel GetLocationAttributeViewModel(
                LocationAttributeNode locationAttributeNode,
                IReadOnlyDictionary <string, GeoJson>?geoJsonByCode)
            {
                var locationAttribute = locationAttributeNode.Attribute;
                var code = locationAttribute.GetCodeOrFallback();

                if (locationAttributeNode.IsLeaf)
                {
                    var geoJson = code.IsNullOrEmpty()
                        ? null
                        : geoJsonByCode?.GetValueOrDefault(code)?.Deserialized;

                    return(new LocationAttributeViewModel
                    {
                        Id = locationAttributeNode.LocationId.Value,
                        GeoJson = geoJson,
                        Label = locationAttribute.Name ?? string.Empty,
                        Value = code
                    });
                }

                return(new LocationAttributeViewModel
                {
                    Label = locationAttribute.Name ?? string.Empty,
                    Level = locationAttribute.GetType().Name.CamelCase(),
                    Value = code,
                    Options = DeduplicateLocationViewModels(
                        locationAttributeNode.Children
                        .OrderBy(OrderLocationAttributes)
                        .Select(child => GetLocationAttributeViewModel(child, geoJsonByCode))
                        )
                              .ToList()
                });
            }
            private static string OrderLocationAttributes(LocationAttributeNode node)
            {
                var locationAttribute = node.Attribute;

                return(locationAttribute switch
                {
                    Region region => region.Code ?? string.Empty,
                    _ => locationAttribute.Name ?? string.Empty
                });
 private static LocationAttributeViewModel BuildLocationAttributeViewModel(
     LocationAttributeNode locationAttributeNode)
 {
     return(locationAttributeNode.IsLeaf
         ? new LocationAttributeViewModel
     {
         Id = locationAttributeNode.LocationId.Value,
         Label = locationAttributeNode.Attribute.Name ?? string.Empty,
         Value = locationAttributeNode.Attribute.GetCodeOrFallback()
     }
         : new LocationAttributeViewModel
     {
         Label = locationAttributeNode.Attribute.Name ?? string.Empty,
         Level = locationAttributeNode.Attribute.GetType().Name.CamelCase(),
         Value = locationAttributeNode.Attribute.GetCodeOrFallback(),
         Options = DeduplicateLocationViewModels(
             locationAttributeNode.Children
             .OrderBy(OrderLocationAttributes)
             .Select(BuildLocationAttributeViewModel)
             )
                   .ToList()
     });
 }