private IEnumerable <FieldData> GetFieldData(IItemVariantIdentifier identifier, ItemModel itemModel)
        {
            var language = itemModel.GetLanguage(identifier.Language);
            var version  = language.GetVersion(identifier.Version);

            var invariantFields = itemModel.Fields.Select(field => new FieldData(
                                                              field.Id,
                                                              identifier.Id,
                                                              field.Value,
                                                              VarianceInfo.Invariant));

            var languageVariantFields = language.Fields.Select(field => new FieldData(
                                                                   field.Id,
                                                                   identifier.Id,
                                                                   field.Value,
                                                                   VarianceInfo.LanguageVariant(language.Language)));

            var variantFields = version.Fields.Select(field => new FieldData(
                                                          field.Id,
                                                          identifier.Id,
                                                          field.Value,
                                                          VarianceInfo.Variant(language.Language, version.Number)));

            return(invariantFields.Union(languageVariantFields).Union(variantFields));
        }
        public async Task <IEnumerable <IItemNode> > GetItemNodes(IReadOnlyCollection <Guid> ids, NodeQueryContext queryContext)
        {
            Condition.Requires(ids, nameof(ids)).IsNotNull();
            Condition.Requires(queryContext, nameof(queryContext)).IsNotNull();

            if (!ids.Any())
            {
                return(Enumerable.Empty <IItemNode>());
            }

            var entities = (await _idTableRepository.GetItemIdData(Connection.IdTablePrefix, ids).ConfigureAwait(false)).EnsureEnumerated();

            if (!entities.Any())
            {
                return(Enumerable.Empty <IItemNode>());
            }

            var models = await _dataProvider.GetItemModels(Connection, entities).ConfigureAwait(false);

            var itemNodes = new List <IItemNode>();

            foreach (var model in models)
            {
                var skinnyItemModel = model.Item1;
                var itemModel       = model.Item2;

                var properties = new ItemProperties(
                    itemModel.ItemName,
                    skinnyItemModel.ParentId,
                    itemModel.TemplateId,
                    null);

                var langVariantFields = new Dictionary <Language, IReadOnlyList <IFieldData> >();
                var variantFields     = new Dictionary <IVarianceIdentity, IReadOnlyList <IFieldData> >();

                foreach (var langModel in itemModel.Languages)
                {
                    var lang = Language.Parse(langModel.Language);

                    // Honour the language filter for the query
                    if (!queryContext.LanguageFilter.Contains(lang))
                    {
                        continue;
                    }

                    var langVariance = VarianceInfo.LanguageVariant(lang);

                    langVariantFields.Add(
                        lang,
                        langModel.Fields
                        .Where(f => queryContext.FieldFilter.Contains(f.Id))     // Honour the field filter for the query
                        .Select(f => new FieldData(
                                    f.Id,
                                    skinnyItemModel.ItemId,
                                    f.Value,
                                    langVariance))
                        .ToArray());

                    foreach (var versionModel in langModel.Versions)
                    {
                        var ver      = Sitecore.Framework.Publishing.Item.Version.Parse(versionModel.Number);
                        var variance = VarianceInfo.Variant(lang, ver);

                        var fields = versionModel.Fields
                                     .Where(f => queryContext.FieldFilter.Contains(f.Id)) // Honour the field filter for the query
                                     .Select(f => new FieldData(f.Id, skinnyItemModel.ItemId, f.Value, variance))
                                     .ToArray();

                        // Sitecore stores the revision as a field, so retrieve the revision value
                        var revision = ClassicItemRepository.GetClassicRevision(fields);

                        variantFields.Add(new VarianceIdentity(lang, ver, revision), fields);
                    }
                }

                itemNodes.Add(new ItemNode(
                                  skinnyItemModel.ItemId,
                                  properties,
                                  itemModel.Fields
                                  .Where(f => queryContext.FieldFilter.Contains(f.Id)) // Honour the field filter for the query
                                  .Select(f => new FieldData(f.Id, skinnyItemModel.ItemId, f.Value, VarianceInfo.Invariant))
                                  .ToArray(),
                                  langVariantFields,
                                  variantFields));
            }

            return(itemNodes);
        }