#ifndef PRODUCTDAO_H
#define PRODUCTDAO_H

#include <QString>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>
#include <QVector>
#include "../gui/forms/formproduct.h"
#include "../data/sqltable.h"

class ProductDAO
{
public:
    // Create a new product
    static bool create(const QString& code, int type1, int type2, const QString& title,
                      const QString& description, const QString& familyId, const QString& unitId,
                      const QDate& dateUpdate, double realPrice, double discount, double purchasePrice,
                      double benefit, double tax, double salePrice, const QString& barcode,
                      const QByteArray& image, bool state, const QString& manufacturer,
                      const QString& gamma, double weight, double height, double width,
                      double lenght);

    // Read a product by code
    static bool read(const QString& code, int& type1, int& type2, QString& title,
                    QString& description, QString& familyId, QString& unitId,
                    QDate& dateUpdate, double& realPrice, double& discount, double& purchasePrice,
                    double& benefit, double& tax, double& salePrice, QString& barcode,
                    QByteArray& image, bool& state, QString& manufacturer, QString& gamma,
                    double& weight, double& height, double& width, double& lenght);

    // Update an existing product
    static bool update(const QString& code, int type1, int type2, const QString& title,
                      const QString& description, const QString& familyId, const QString& unitId,
                      const QDate& dateUpdate, double realPrice, double discount, double purchasePrice,
                      double benefit, double tax, double salePrice, const QString& barcode,
                      const QByteArray& image, bool state, const QString& manufacturer,
                      const QString& gamma, double weight, double height, double width,
                      double lenght);

    // Delete a product
    static bool remove(const QString& code);

    // Check if product exists
    static bool exists(const QString& code);

    // Get all products
    static QVector<QString> getAllCodes();

    // Get product composition
    static QVector<QPair<QString, double>> getComposition(const QString& code);

    // Add composition element
    static bool addCompositionElement(const QString& productCode, const QString& elementCode, double amount);

    // Remove composition element
    static bool removeCompositionElement(const QString& productCode, const QString& elementCode);

    // Update composition element amount
    static bool updateCompositionElement(const QString& productCode, const QString& elementCode, double amount);

    // Remove all composition elements for a product
    static bool removeAllComposition(const QString& productCode);

    // Get basic element info (title, unit) for display in composition tree
    static bool getElementBasicInfo(const QString& code, QString& title, QString& unitId);
};

#endif // PRODUCTDAO_H