File indexing completed on 2024-11-24 04:45:10

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "kitinerary_export.h"
0010 #include "ssbticketbase.h"
0011 
0012 #include <QDateTime>
0013 #include <QMetaType>
0014 
0015 namespace KItinerary {
0016 
0017 /** ERA SSB ticket barcode (version 2).
0018  *  @see ERA TAP TSI TD B.12 - ยง15 Appendix B - SSB - old version
0019  */
0020 class KITINERARY_EXPORT SSBv2Ticket : protected SSBTicketBase
0021 {
0022     Q_GADGET
0023     SSB_NUM_PROPERTY(version, 0, 4)
0024     SSB_NUM_PROPERTY(issuerCode, 4, 14)
0025     SSB_NUM_PROPERTY(publicKeyVersion, 18, 4)
0026     SSB_NUM_PROPERTY(rct2TypeIndicator, 22, 1)
0027     SSB_NUM_PROPERTY(numberOfTickets, 23, 6)
0028     SSB_NUM_PROPERTY(numberOfAdultPassengers, 29, 7)
0029     SSB_NUM_PROPERTY(numberOfChildPassengers, 36, 7)
0030     SSB_NUM_PROPERTY(firstDayOfValidityDay, 43, 9)
0031     SSB_NUM_PROPERTY(lastDayOfValidityDay, 52, 9)
0032     SSB_NUM_PROPERTY(customerNumberType, 61, 1)
0033     SSB_LONG_PROPERTY(customerNumber, 62, 47)
0034     SSB_NUM_PROPERTY(departureStationType, 109, 1)
0035     SSB_NUM_PROPERTY(departureStationNum, 110, 30)
0036     SSB_STR_PROPERTY(departureStationAlpha, 110, 5)
0037     SSB_NUM_PROPERTY(arrivalStationType, 140, 1)
0038     SSB_NUM_PROPERTY(arrivalStationNum, 141, 30)
0039     SSB_STR_PROPERTY(arrivalStationAlpha, 141, 5)
0040     SSB_NUM_PROPERTY(departureTime, 171, 6)
0041     SSB_NUM_PROPERTY(trainNumber, 177, 25) // alpha 5 encoding??
0042     SSB_LONG_PROPERTY(reservationReference, 202, 40)
0043     SSB_NUM_PROPERTY(classOfTransport, 242, 6)
0044     SSB_NUM_PROPERTY(coachNumber, 248, 10)
0045     SSB_NUM_PROPERTY(seatNumber, 258, 7) // 250 in trenitalia??
0046     SSB_STR_PROPERTY(berthNumber, 265, 1)
0047     SSB_NUM_PROPERTY(overbookingIndicator, 211, 1)
0048     SSB_STR_PROPERTY(issuerPNRNumber, 272, 7)
0049     SSB_NUM_PROPERTY(ticketType, 314, 4)
0050     SSB_NUM_PROPERTY(specimen, 318, 1)
0051     SSB_STR_PROPERTY(viaStations, 319, 5) // is that the correct encoding? page 131 of TAP TSI Annex B.6 could also be read as 6 times 5 bit content
0052     SSB_NUM_PROPERTY(railwayCarrierCode, 349, 14)
0053     SSB_STR_PROPERTY(reference, 363, 8)
0054 
0055     Q_PROPERTY(QByteArray rawData READ rawData STORED false)
0056 
0057 public:
0058     SSBv2Ticket();
0059     explicit SSBv2Ticket(const QByteArray &data);
0060     ~SSBv2Ticket();
0061 
0062     /** Returns @c true if this is a valid SSB ticket. */
0063     bool isValid() const;
0064 
0065     /** First day of validity. */
0066     Q_INVOKABLE QDate firstDayOfValidity(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
0067     /** Last day of validity. */
0068     Q_INVOKABLE QDate lastDayOfValidity(const QDateTime &contextDate = QDateTime::currentDateTime()) const;
0069 
0070     /** Raw barcode data. */
0071     QByteArray rawData() const;
0072 
0073     /** Returns @c true if @p data might be an ERA SSB ticket. */
0074     static bool maybeSSB(const QByteArray &data);
0075 };
0076 
0077 }
0078 
0079 Q_DECLARE_METATYPE(KItinerary::SSBv2Ticket)
0080