-
Notifications
You must be signed in to change notification settings - Fork 2
/
TravelCard.cs
97 lines (81 loc) · 4.17 KB
/
TravelCard.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
namespace HslTravelSharp.Core.Models
{
/// <summary>
/// A friendly representation of the values contained on a travel card.
/// A travel card can contain two "period" (aka season pass) products:
/// Period1, and Period2. Usually, they are the two most-recently purchased products.
/// Note: For serialization, use the RawValues property, and reconstruct the Travel
/// Card on the other side using the constructor that takes a RawTravelCard.
/// </summary>
public class TravelCard
{
public RawTravelCard RawValues { get; private set; } = new RawTravelCard();
public string CardNumber => RawValues.ApplicationInstanceId;
// Season pass 1
public DateTimeOffset PeriodStartDate1 => RawValues.PeriodStartDate1;
public DateTimeOffset PeriodEndDate1 => RawValues.PeriodEndDate1;
public ValidityArea ValidityArea1 { get; private set; }
// Season pass 2
public DateTimeOffset PeriodStartDate2 => RawValues.PeriodStartDate2;
public DateTimeOffset PeriodEndDate2 => RawValues.PeriodEndDate2;
public ValidityArea ValidityArea2 { get; private set; }
// Season pass previous boarding info
/// <summary>
/// The date of the most recent boarding.
/// </summary>
public DateTimeOffset LastBoardingDate => RawValues.BoardingDate;
/// <summary>
/// The ID of the vehicle boarded at the most recent boarding.
/// </summary>
public ushort LastBoardingVehicleId => RawValues.BoardingVehicle;
/// <summary>
/// Indicator of how to interpret <see cref="LastBoardingLocationNumber"/>.
/// </summary>
public BoardingNumberLocationType LastBoardingType => (BoardingNumberLocationType)RawValues.BoardingLocationNumType;
/// <summary>
/// Number of the last boarding location. This value should be interpreted
/// according to the LastBoardingType enum. It might be a bus number,
/// train number or platform number.
/// </summary>
public ushort LastBoardingLocationNumber => RawValues.BoardingLocationNum;
/// <summary>
/// The direction the method of transit was heading when it was boarded at the most recent boarding.
/// </summary>
public BoardingDirection LastBoardingDirection => (BoardingDirection)RawValues.BoardingDirection;
/// <summary>
/// The zone which the most recent boarding ticket was purchased for.
/// </summary>
public ValidityArea LastBoardingArea { get; private set; }
// Stored value (i.e. money) info
/// <summary>
/// Total monetary value on the card expressed in Euro cents.
/// </summary>
public decimal ValueTotalCents => RawValues.ValueCounter;
public DateTimeOffset ValueLoadDateTime => RawValues.LoadingDate.AddMinutes(RawValues.LoadingTime);
public decimal ValueLoadedCents => RawValues.LoadedValue;
public IEnumerable<History> History => RawValues.HistoryFields;
/// <summary>
/// The currently (or most recently) active value ticket on the card.
/// </summary>
public ETicket ValueTicket => RawValues.FriendlyTicket;
/// <summary>
/// Creates a friendly Travel Card given a <see cref="RawTravelCard"/> object.
/// </summary>
/// <param name="rawCard"></param>
public TravelCard(RawTravelCard rawValues)
{
RawValues = rawValues;
var valid1Type = (ValidityAreaType)RawValues.ValidityAreaType1;
ValidityArea1 = valid1Type == ValidityAreaType.Zone
? new ValidityArea((Zone)RawValues.ValidityArea1)
: new ValidityArea((Vehicle)RawValues.ValidityArea1);
var valid2Type = (ValidityAreaType)RawValues.ValidityAreaType2;
ValidityArea2 = valid2Type == ValidityAreaType.Zone
? new ValidityArea((Zone)RawValues.ValidityArea2)
: new ValidityArea((Vehicle)RawValues.ValidityArea2);
LastBoardingArea = new ValidityArea((Vehicle)RawValues.BoardingArea);
}
}
}