#ifndef BUDGETDAO_H
#define BUDGETDAO_H

#include <QString>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVector>
#include <QDate>

class BudgetDAO
{
public:
    struct Data {
        int id = 0;
        QString type;            // PR - Presupuesto, FA - Factura
        QString code;
        QString title;
        int version = 1;
        QString customerCode;
        QString customerName;
        QString projectCode;
        QString projectTitle;
        double cost = 0.0;
        double price = 0.0;
        int tax = 0;
        QString state;
        int stateNumber = 0;
        QString description;
        QDate createdAt;
        QDate validUntil;
        QDate deliveryDate;
        QString createdBy;
    };

    struct LineData {
        int id = 0;
        QString saleDocumentCode;
        int version = 1;
        QString nodeIndex;
        QString elementCode;
        QString elementType;
        int elementIndex = 0;
        QString elementTitle;
        QString elementDescription;
        double elementUnitAmount = 1.0;
        double elementTotalAmount = 1.0;
        QString elementUnit;
        double elementPrice = 0.0;
        double benefit = 0.0;
        double discount = 0.0;
        double tax = 0.0;
        bool print = true;
        QDate createdAt;
        QString createdBy;
    };

    static bool create(const Data& data);
    static bool read(int id, Data& data);
    static bool readByCode(const QString& code, Data& data);
    static bool update(const Data& data);
    static bool remove(int id);
    static bool exists(const QString& code);

    static QVector<int> getAllIds();
    static QVector<Data> getAll();

    // Lines
    static bool createLine(const LineData& data);
    static QVector<LineData> getLines(const QString& documentCode);
    static bool removeLines(const QString& documentCode);
};

#endif // BUDGETDAO_H