#include "calculate_parking_tickets_utils.h"
#include "calculate_parking_tickets_tariff.h"

#include <QTimeZone>
#include <QDebug>

namespace TUtils {
    bool isHoliday(parking_tariff_t const *tariff, QDate const &qd) {
        for (int s = 0; s < tariff->holidays.size(); ++s) {
            if (tariff->holidays.contains(qd)) {
                qDebug() << "Holiday";
                return true;
            }
        }
        qDebug() << "No Holiday";
        return false;
    }

    QDateTime const fromSecs(quint64 secs) {
        QDateTime dateTime;
        dateTime.setSecsSinceEpoch(0);
        return dateTime.addSecs(secs);
    }

    QDateTime const fromMinutes(quint64 minutes) {
        return fromSecs(minutes*60);
    }

    quint64 toSecs(QDateTime const &dt) {
        return dt.toSecsSinceEpoch();
    }

    quint64 toMinutes(QDateTime const &dt) {
        return dt.toSecsSinceEpoch()/60;
    }

    // Monday
    bool isMon(quint64 secs) {
        return (fromSecs(secs).date().dayOfWeek() == Qt::Monday);
    }
    bool isMon(QDate const &date) {
        return (date.dayOfWeek() == Qt::Monday);
    }
    bool isMonUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Monday);
    }
    bool isMonCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Monday);
    }
    bool isMonUTC(QDate const &dateSinceEpoch) {
        return (dateSinceEpoch.dayOfWeek() == Qt::Monday);
    }
    bool isMonCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Monday);
    }

    // Tuesday
    bool isTue(QDate const &date) {
        return (date.dayOfWeek() == Qt::Tuesday);
    }
    bool isTueUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Tuesday);
    }
    bool isTueCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Tuesday);
    }
    bool isTueUTC(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Tuesday);
    }
    bool isTueCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Tuesday);
    }

    // Wednesday
    bool isWed(QDate const &date) {
        return (date.dayOfWeek() == Qt::Wednesday);
    }
    bool isWedUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Wednesday);
    }
    bool isWedCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Wednesday);
    }
    bool isWedUTC(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Wednesday);
    }
    bool isWedCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Wednesday);
    }

    // Thursday
    bool isThu(QDate const &date) {
        return (date.dayOfWeek() == Qt::Thursday);
    }
    bool isThuUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Thursday);
    }
    bool isThuCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Thursday);
    }
    bool isThuUTC(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Thursday);
    }
    bool isThuCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Thursday);
    }

    // Friday
    bool isFri(QDate const &date) {
        return (date.dayOfWeek() == Qt::Friday);
    }
    bool isFriUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Friday);
    }
    bool isFriCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Friday);
    }
    bool isFriUTC(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Friday);
    }
    bool isFriCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Friday);
    }

    // Saturday
    bool isSat(QDate const &date) {
        return (date.dayOfWeek() == Qt::Saturday);
    }
    bool isSatUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Saturday);
    }
    bool isSatCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Saturday);
    }
    bool isSatUTC(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Saturday);
    }
    bool isSatCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Saturday);
    }

    // Sunday
    bool isSun(QDate const &date) {
        return (date.dayOfWeek() == Qt::Sunday);
    }
    bool isSunUTC(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::UTC).date().dayOfWeek() == Qt::Sunday);
    }
    bool isSunCET(quint64 secsSinceEpoch) {
        return (QDateTime::fromSecsSinceEpoch(secsSinceEpoch, Qt::LocalTime).date().dayOfWeek() == Qt::Sunday);
    }
    bool isSunUTC(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Sunday);
    }
    bool isSunCET(QDate const &dateSinceEpoch) {
      return (dateSinceEpoch.dayOfWeek() == Qt::Sunday);
    }
}
