#ifndef REFUND_GENERATOR_H #define REFUND_GENERATOR_H #include "base_generator.h" #include "date_time_generator.h" #include #include #include // Forward declaration class RefundsRepository; class SessionsRepository; class TicketsRepository; class RefundGenerator : public BaseGenerator, public DateTimeGenerator { private: struct ReservationContext { QDateTime beginAt; QDateTime refundAt; QDateTime soldAt; double refundAmount; qint32 ticketId; }; struct CacheValue { QDateTime beginAt; QDateTime soldAt; double ticketPrice; }; private: QMap // WARNING: There can be a lot ticketIdToCacheValue_; // of records, so 1 QPair is used, not 3 QMap QPair refundRatioRange_; ReservationContext reservationContext_; qsizetype remainingCapacity_; RefundsRepository *refundsRepository_; SessionsRepository *sessionsRepository_; TicketsRepository *ticketsRepository_; public: RefundGenerator(const QPair &refundRatioRange, const QPair &dayRange, const QPair &timeRange); private: void initializeRepositories(); void initializeTicketIdToCacheValueMap(); inline void initializeRemainingCapacity(); private: inline qint64 calculateDurationMs(const CacheValue &cacheValue) const; // Vitual methods private: // Const methods QString createFailureMessage(const QString &errorMessage) const override; QString createSuccessMessage() const override; qsizetype calculateRemainingCapacity() const override; private: // Non-const methods RepositoryResult createRecord() override; bool prepareData() override; void clearStaleData() override; }; void RefundGenerator::initializeRemainingCapacity() { remainingCapacity_ = ticketIdToCacheValue_.size(); } qint64 RefundGenerator::calculateDurationMs(const CacheValue &cacheValue) const { return cacheValue.soldAt.msecsTo(cacheValue.beginAt); } #endif