#ifndef ELEMENTDAO_H
#define ELEMENTDAO_H

#include <QString>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVector>
#include <QPair>
#include "../src/elementtype.h"

class ElementDAO
{
public:
    struct ElementData {
        QString code;
        QString title;
        QString description;
        QString unitId;
        int type1; // Matches ElementType enum: 0=Composed, 1=Material, 2=ManPower, 3=Machinery, 4=Subcontracted, 5=Other
        double purchasePrice = 0.0;
        // Add other fields as needed from ELEMENT table
    };

    struct CompositionItem {
        QString childElementCode;
        double amount; // Quantity of child element needed for parent
    };

    static bool create(const ElementData& element);
    static bool read(const QString& code, ElementData& element);
    static bool update(const ElementData& element);
    static bool remove(const QString& code);
    static bool exists(const QString& code);

    // Composition methods
    static QVector<CompositionItem> getComposition(const QString& elementCode);
    static bool addCompositionElement(const QString& elementCode, const QString& childElementCode, double amount);
    static bool removeCompositionElement(const QString& elementCode, const QString& childElementCode);
    static bool updateCompositionElement(const QString& elementCode, const QString& childElementCode, double amount);
    static bool removeAllComposition(const QString& elementCode);
};

#endif // ELEMENTDAO_H