#ifndef EDITPRODUCTDIALOG_H
#define EDITPRODUCTDIALOG_H

#include <QSqlTableModel>

#include <QDialog>

namespace Ui {
class EditProductDialog;
}

class ColouredLineEdit;

class EditProductDialog : public QDialog {
  Q_OBJECT

private:
  enum class Input : int { LineEdit, DateEdit, SpinBox, DoubleSpinBox };

private:
  bool newBarcodeCorrect;
  int m_productId;
  long long m_barcode;
  QString m_name;
  std::vector<QVariant> m_clearData;

private:
  QSqlTableModel *m_model;
  ColouredLineEdit *m_barcodeLineEdit;
  Ui::EditProductDialog *m_ui;

private:
  void done(int resultCode) override;

private:
  void initializeRecordValues(const QSqlRecord &productsJoinProductTypes);
  void configureSqlModel();
  void createWidgets();
  void configureWidgets();
  void configureConnections();
  void configureDisplayedData();

private:
  void setEnableProperties(bool enable);
  void refreshInputWidgets(const QModelIndex &currentIndex);
  void modifyModelValue();
  void checkBarcode();

private:
  void currentRecordInfo(int *productIdIndex, int *attributeIdIndex,
                         int *nameIndex, int *valueIndex);

public:
  explicit EditProductDialog(const QSqlRecord &product,
                             QWidget *parent = nullptr);
  ~EditProductDialog();
};

#endif // EDITPRODUCTDIALOG_H
