MOBILISIS-Calculator/library/include/mobilisis/ticket.h

67 lines
2.0 KiB
C
Raw Permalink Normal View History

2023-11-26 19:56:38 +01:00
#ifndef TICKET_H_INCLUDED
#define TICKET_H_INCLUDED
#include <tuple>
#include <vector>
#include <QDebug>
#include <QDebugStateSaver>
#include <QStringList>
#include <QDateTime>
#define NOT_INITIALIZED (0)
#define VALID (1)
#define INVALID_FROM_DATETIME (2)
#define INVALID_UNTIL_DATETIME (3)
2023-11-28 16:41:27 +01:00
#define INVALID_PRICE (4)
#define STATUS_END (5)
2023-11-26 19:56:38 +01:00
class Ticket {
enum {CODE=0, CODE_STR=1, CODE_DESC=3};
public:
using Status = std::tuple<int, char const*, char const*>;
explicit Ticket();
2023-11-27 16:14:27 +01:00
explicit Ticket(QDateTime const &s, QDateTime const &e,
int durationMinutesNetto, int durationMinutesBrutto,
uint32_t price, Status status);
2023-11-26 19:56:38 +01:00
explicit operator bool() { return std::get<CODE>(m_status) == VALID; }
operator QString();
Status getStatus() const;
QDateTime getValidFrom() const;
QDateTime getValidUntil() const;
uint32_t getPrice() const;
Status setStatus(Status status);
void setValidFrom(QDateTime const &validFrom);
void setValidUntil(QDateTime const &validUnil);
void setPrice(uint32_t price);
2023-11-27 16:14:27 +01:00
bool isValid() { return operator bool(); }
static constexpr const Status s[STATUS_END] = {
{NOT_INITIALIZED , "NOT_INITIALIZED" , "Ticket not initialized" },
{VALID , "VALID" , "Ticket is valid" },
{INVALID_FROM_DATETIME , "INVALID_FROM_DATETIME" , "Ticket has invalid start datetime"},
2023-11-28 16:41:27 +01:00
{INVALID_UNTIL_DATETIME, "INVALID_UNTIL_DATETIME", "Ticket has invalid end datetime" },
{INVALID_PRICE , "INVALID_PRICE" , "PARKING NOT ALLOWED: Ticket has invalid price" }
2023-11-27 16:14:27 +01:00
};
2023-11-26 19:56:38 +01:00
private:
Status m_status;
QDateTime m_validFrom;
QDateTime m_validUntil;
int m_durationMinutesNetto;
int m_durationMinutesBrutto;
uint32_t m_price;
};
2023-11-27 16:14:27 +01:00
QDebug operator<<(QDebug debug, Ticket::Status const &status);
2023-11-26 19:56:38 +01:00
#endif // TICKET_H_INCLUDED