#ifndef VOUCHER_H
#define VOUCHER_H

#include <QObject>
#include <QDecDouble.hh>
#include <QString>
#include <QSharedPointer>
#include <addressbookdata.h>
#include <odb/core.hxx>
#include <odb/qt/list.hxx>

#include "voucheritem.h"

#pragma db object
class Voucher : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString numSer READ numSer WRITE setNumSer)
    Q_PROPERTY(QDateTime payDateTime READ payDateTime WRITE setPayDateTime)
    Q_PROPERTY(QString name READ name WRITE setName)
    Q_PROPERTY(QString description READ description WRITE setDescription)
    Q_PROPERTY(QSharedPointer<QObject> contact READ contact WRITE setContact)
    Q_PROPERTY(QDecDouble vatRateHigh READ vatRateHigh WRITE setVatRateHigh)
    Q_PROPERTY(QDecDouble vatRateFirstLower READ vatRateFirstLower WRITE setVatRateFirstLower)
    Q_PROPERTY(QDecDouble vatRateSecondLower READ vatRateSecondLower WRITE setVatRateSecondLower)
    Q_PROPERTY(QDecDouble priceVatHigh READ priceVatHigh WRITE setPriceVatHigh)
    Q_PROPERTY(QDecDouble priceVatFirstLower READ priceVatFirstLower WRITE setPriceVatFirstLower)
    Q_PROPERTY(QDecDouble priceVatSecondLower READ priceVatSecondLower WRITE setPriceVatSecondLower)
    Q_PROPERTY(QDecDouble totalPrice READ totalPrice WRITE setTotalPrice)
    Q_ENUMS(VoucherStatus)
    Q_PROPERTY(VoucherStatus status READ status WRITE setStatus)

public:
    explicit Voucher(QObject *parent = 0);

    enum VoucherStatus
    {
        NEW,
        TEMPORARY,
        NOT_PAID,
        PAID
    };

    int id() const;
    void setId(int id);

    QString name() const;
    void setName(const QString &name);

    QString description() const;
    void setDescription(const QString &description);

    QSharedPointer<QObject> contact() const;
    void setContact(const QSharedPointer<QObject> &contact);

    VoucherStatus status() const;
    void setStatus(const VoucherStatus &status);

    QDecDouble totalPrice() const;
    void setTotalPrice(QDecDouble totalPrice);

    QList<QSharedPointer<VoucherItem> > items() const;
    void setItems(const QList<QSharedPointer<VoucherItem> > &items);

    void addItem(QSharedPointer<VoucherItem> item);
    void removeItem(QSharedPointer<VoucherItem> item);
    void clearItems();

    QDecDouble vatRateHigh() const;
    void setVatRateHigh(QDecDouble vatRateHigh);

    QDecDouble vatRateFirstLower() const;
    void setVatRateFirstLower(QDecDouble vatRateFirstLower);

    QDecDouble vatRateSecondLower() const;
    void setVatRateSecondLower(QDecDouble vatRateSecondLower);

    QDecDouble priceVatHigh() const;
    void setPriceVatHigh(QDecDouble priceVatHigh);

    QDecDouble priceVatFirstLower() const;
    void setPriceVatFirstLower(QDecDouble priceVatFirstLower);

    QDecDouble priceVatSecondLower() const;
    void setPriceVatSecondLower(QDecDouble priceVatSecondLower);

    QDecDouble priceNoVat() const;
    void setPriceNoVat(QDecDouble priceNoVat);

    QDecDouble priceWitouthVat() const;
    void setPriceWitouthVat(QDecDouble priceWitouthVat);

    QDecDouble totalPriceVatHigh() const;
    void setTotalPriceVatHigh(QDecDouble totalPriceVatHigh);

    QDecDouble totalPriceVatFirstLower() const;
    void setTotalPriceVatFirstLower(QDecDouble totalPriceVatFirstLower);

    QDecDouble totalPriceVatSecondLower() const;
    void setTotalPriceVatSecondLower(QDecDouble totalPriceVatSecondLower);

    QDecDouble vatAmountHigh();
    QDecDouble vatAmountFirstLower();
    QDecDouble VatAmountSecondLower();

    QString numSer() const;
    void setNumSer(const QString &numSer);

    QDateTime payDateTime() const;
    void setPayDateTime(const QDateTime &payDateTime);

private:
    friend class odb::access;
#pragma db id auto
    int m_id;
    QString m_numSer;
    QDateTime m_payDateTime;
    QString m_name;
    QString m_description;
    QSharedPointer<AddressbookData> m_contact;
    int m_vatRateHigh;
    int m_vatRateFirstLower;
    int m_vatRateSecondLower;
    int m_priceNoVat;
    int m_priceVatHigh;
    int m_priceVatFirstLower;
    int m_priceVatSecondLower;
    int m_priceWitouthVat;
    int m_totalPriceVatHigh;
    int m_totalPriceVatFirstLower;
    int m_totalPriceVatSecondLower;
    int m_totalPrice;
    #pragma db value_not_null inverse(m_voucher)
    QOdbList<QSharedPointer<VoucherItem> > m_items;
    VoucherStatus m_status;
};

#endif // VOUCHER_H
