diff --git a/library/include/mobilisis/tariff_carryover_settings.h b/library/include/mobilisis/tariff_carryover_settings.h new file mode 100644 index 0000000..076caad --- /dev/null +++ b/library/include/mobilisis/tariff_carryover_settings.h @@ -0,0 +1,61 @@ +#ifndef ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED +#define ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED + +#include +#include + +#include + +struct ATBTariffCarryOverSettings { + + // parking time limit not violated: return false, otherwise: return true. + using ParkingTimeLimitChecker = std::function; + + int m_duration; + QTime m_start; + QTime m_end; + ParkingTimeLimitChecker m_parkingTimeLimitChecker; + + QTime m_parking_time_limit; + QTime m_about_to_exceed_parking_time_limit; + + explicit ATBTariffCarryOverSettings() + : m_duration(0) + , m_start(QTime()) + , m_end(QTime()) + , m_parkingTimeLimitChecker([](ATBTariffCarryOverSettings const&, QDateTime const &, int) { return false; }) + , m_parking_time_limit(QTime()) + , m_about_to_exceed_parking_time_limit(QTime()) {} + + explicit ATBTariffCarryOverSettings(int duration, QTime const &start, + QTime const &end, + QTime const &parking_time_limit, + QTime const &about_to_exceed_parking_time_limit, + ParkingTimeLimitChecker parkingTimeLimitChecker) + : m_duration(duration) + , m_start(start) + , m_end(end) + , m_parkingTimeLimitChecker(std::move(parkingTimeLimitChecker)) + , m_parking_time_limit(parking_time_limit) + , m_about_to_exceed_parking_time_limit(about_to_exceed_parking_time_limit) { + } + + bool parkingTimeLimitExceeded(QDateTime const &endTime, int paymentOptionIndex) const { + return m_parkingTimeLimitChecker(*this, endTime, paymentOptionIndex); + } + + friend QDebug operator<<(QDebug debug, ATBTariffCarryOverSettings const &co) { + QDebugStateSaver saver(debug); + + debug.nospace() + << " duration: " << co.m_duration << "\n" + << " start: " << co.m_start.toString(Qt::ISODate) << "\n" + << " end: " << co.m_end.toString(Qt::ISODate) << "\n" + << " parking_time_limit: " << co.m_parking_time_limit.toString(Qt::ISODate) << endl; + + return debug; + } +}; + +#endif // ATB_TARIFF_CARRYOVER_SETTINGS_H_INCLUDED