using System.Collections.ObjectModel;
using System.Linq;
using TINK.Model.Bikes.BikeInfoNS;
namespace TINK.ViewModel.Bikes.Bike
{
///
/// View model for displaying tariff info.
///
public class TariffDescriptionViewModel
{
private const string TRACKINGKEY = "TRACKING";
private const string RIDETYPEKEY = "AAFAHRTEN";
public TariffDescriptionViewModel(RentalDescription tariff)
{
Name = tariff?.Name ?? string.Empty;
TariffEntries = tariff != null && tariff?.TariffEntries != null
? new ObservableCollection(tariff.TariffEntries.OrderBy(x => x.Key).Select(x => x.Value))
: new ObservableCollection();
// Add all entires except the known entries which are kept as properties.
InfoEntries = tariff != null && tariff?.InfoEntries != null
? new ObservableCollection(tariff.InfoEntries
.Where(x => x.Value.Key.ToUpper() != TRACKINGKEY
&& x.Value.Key.ToUpper() != RIDETYPEKEY)
.OrderBy(x => x.Key)
.Select(x => x.Value.Value))
: new ObservableCollection();
RideTypeText = tariff?.InfoEntries != null ? tariff?.InfoEntries?.FirstOrDefault(x => x.Value.Key.ToUpper() == RIDETYPEKEY).Value?.Value ?? string.Empty : string.Empty;
TrackingInfoText = tariff?.InfoEntries != null ? tariff?.InfoEntries?.FirstOrDefault(x => x.Value.Key.ToUpper() == TRACKINGKEY).Value?.Value ?? string.Empty : string.Empty;
}
///
/// Holds the name of the tariff.
///
public string Name { get; set; }
///
/// Holds the tariff entries to display.
///
public ObservableCollection TariffEntries { get; private set; }
///
/// Holds the info entries to display.
///
public ObservableCollection InfoEntries { get; private set; }
///
/// Holds the tracking info text or empty if not applicable.
///
public string RideTypeText { get; private set; }
///
/// Holds the tracking info text or empty if not applicable.
///
public string TrackingInfoText { get; private set; }
public RentalDescription.TariffElement TarifEntry1 => TariffEntries.Count > 0 ? TariffEntries[0] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry2 => TariffEntries.Count > 1 ? TariffEntries[1] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry3 => TariffEntries.Count > 2 ? TariffEntries[2] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry4 => TariffEntries.Count > 3 ? TariffEntries[3] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry5 => TariffEntries.Count > 4 ? TariffEntries[4] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry6 => TariffEntries.Count > 5 ? TariffEntries[5] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry7 => TariffEntries.Count > 6 ? TariffEntries[6] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry8 => TariffEntries.Count > 7 ? TariffEntries[7] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry9 => TariffEntries.Count > 8 ? TariffEntries[8] : new RentalDescription.TariffElement();
public string InfoEntry1 => InfoEntries.Count > 0 ? InfoEntries[0] : string.Empty;
public string InfoEntry2 => InfoEntries.Count > 1 ? InfoEntries[1] : string.Empty;
public string InfoEntry3 => InfoEntries.Count > 2 ? InfoEntries[2] : string.Empty;
public string InfoEntry4 => InfoEntries.Count > 3 ? InfoEntries[3] : string.Empty;
public string InfoEntry5 => InfoEntries.Count > 4 ? InfoEntries[4] : string.Empty;
}
}