using Manager.DTOs;
using ManagerService.DTOs;
using System;
using System.Collections.Generic;
using System.Linq;
namespace ManagerService.Data
{
///
/// Briques communes à et
/// . Sorties de parce que
/// les structures parcourues (GeoPoint, GuidedStep, EventAgenda…) n'en héritent pas.
///
public static class SectionText
{
public static string Translate(IEnumerable translations, string language) =>
translations?.FirstOrDefault(t => string.Equals(t.language, language, StringComparison.OrdinalIgnoreCase))?.value;
public static string Translate(IEnumerable translations, string language) =>
translations?.FirstOrDefault(t => string.Equals(t.language, language, StringComparison.OrdinalIgnoreCase))?.value;
public static string TranslateContents(IEnumerable contents, string language) =>
JoinText((contents ?? Enumerable.Empty())
.OrderBy(c => c.order ?? 0)
.SelectMany(c => new[] { Translate(c.title, language), Translate(c.description, language) })
.ToArray());
public static string JoinText(params string[] parts) =>
string.Join("\n", parts.Where(p => !string.IsNullOrWhiteSpace(p)));
public static IEnumerable ResourceId(string id) =>
string.IsNullOrWhiteSpace(id) ? Enumerable.Empty() : new[] { id };
///
/// Champs où la valeur traduite est un id de ressource (audios, PDF, JSON d'agenda),
/// et non du texte à afficher.
///
public static IEnumerable ResourceIdsFromValues(IEnumerable translations, string language) =>
(translations ?? Enumerable.Empty())
.Where(t => language == null || string.Equals(t.language, language, StringComparison.OrdinalIgnoreCase))
.SelectMany(t => ResourceId(t.value));
public static IEnumerable ResourceIds(IEnumerable translations, string language) =>
(translations ?? Enumerable.Empty())
.Where(t => language == null || string.Equals(t.language, language, StringComparison.OrdinalIgnoreCase))
.SelectMany(t => ResourceId(t.resourceId));
public static IEnumerable ResourceIds(IEnumerable contents) =>
(contents ?? Enumerable.Empty()).SelectMany(c => ResourceId(c.resourceId));
}
}