2022-08-30 15:42:25 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Connector.Updater
|
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public static class RentalDescriptionFactory
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates rental description object from JSON- tarif description object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="rentalDesciption">Source JSON object.</param>
|
|
|
|
|
/// <returns>Tariff description object.</returns>
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public static Bikes.BikeInfoNS.RentalDescription Create(this Repository.Response.RentalDescription rentalDesciption)
|
|
|
|
|
{
|
|
|
|
|
Bikes.BikeInfoNS.RentalDescription.TariffElement CreateTarifEntry(string[] elementValue)
|
|
|
|
|
{
|
|
|
|
|
return new Bikes.BikeInfoNS.RentalDescription.TariffElement
|
|
|
|
|
{
|
|
|
|
|
Description = elementValue != null && elementValue.Length > 0 ? elementValue[0] : string.Empty,
|
|
|
|
|
Value = elementValue != null && elementValue.Length > 1 ? elementValue[1] : string.Empty,
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Bikes.BikeInfoNS.RentalDescription.InfoElement CreateInfoElement(string[] elementValue)
|
|
|
|
|
{
|
|
|
|
|
return new Bikes.BikeInfoNS.RentalDescription.InfoElement
|
|
|
|
|
{
|
|
|
|
|
Key = elementValue != null && elementValue.Length > 0 ? elementValue[0] : string.Empty,
|
|
|
|
|
Value = elementValue != null && elementValue.Length > 1 ? elementValue[1] : string.Empty,
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Read tariff elements.
|
|
|
|
|
var tarifEntries = rentalDesciption?.tarif_elements != null
|
|
|
|
|
? rentalDesciption.tarif_elements.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
Key = x.Key,
|
|
|
|
|
Value = CreateTarifEntry(x.Value)
|
|
|
|
|
}).ToLookup(x => x.Key, x => x.Value).ToDictionary(x => x.Key, x => x.First())
|
|
|
|
|
: new Dictionary<string, Bikes.BikeInfoNS.RentalDescription.TariffElement>();
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
// Read info elements.
|
|
|
|
|
var InfoEntries = rentalDesciption?.rental_info != null
|
|
|
|
|
? rentalDesciption.rental_info.Select(x => new
|
|
|
|
|
{
|
|
|
|
|
Key = x.Key,
|
|
|
|
|
Value = CreateInfoElement(x.Value)
|
|
|
|
|
}).ToLookup(x => x.Key, x => x.Value).ToDictionary(x => x.Key, x => x.First())
|
|
|
|
|
: new Dictionary<string, Bikes.BikeInfoNS.RentalDescription.InfoElement>();
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
var bike = new Bikes.BikeInfoNS.RentalDescription
|
|
|
|
|
{
|
|
|
|
|
Name = rentalDesciption?.name ?? string.Empty,
|
|
|
|
|
Id = int.TryParse(rentalDesciption?.id ?? string.Empty, out int number) ? number : (int?)null,
|
|
|
|
|
TariffEntries = tarifEntries,
|
|
|
|
|
InfoEntries = InfoEntries
|
|
|
|
|
};
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
return bike;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
}
|