#ifndef SQLSCRIPT_H
#define SQLSCRIPT_H

#include "../databaseinfo/databaseinfo.h"

#include <vector>

#include <QString>

#include <QSqlQuery>

class SqlScript {
public:
  SqlScript() = delete;
  ~SqlScript() = delete;

public:
  using TableType = DatabaseInfo::Table;
  using ColumnType = DatabaseInfo::Column;

public:
  static QSqlQuery lastTableQuery() noexcept;

public: // product types
  static bool doesBarcodeExist(long long barcode);
  static bool doesProductTypeExist(const QString &typeName);
  static void renameProductType(int productTypeId, const QString &typeName);
  static int specifyProductType(int productTypeId, const QString &typeName);
  static int insertProductType(int productTypeId, const QString &typeName);
  static void deleteProductType(int productTypeId);

public: // products
  static bool doesProductExist(const QString &productName);
  static bool doesProductExist(int productTypeId);
  static void updateBarcode(int productId, long long barcode);
  static void renameProduct(int productId, const QString &productName);
  static int insertProduct(const QString &name, int productTypId,
                           long long barcode);
  static void insertProductAttribute(int productId, int attributeId);
  static void insertProductValue(int productId, int attributeId,
                                 const QVariant &value);
  static QSqlQuery deleteProduct(int productId);
  static QSqlQuery subgroupsProductsJoinProductTypes(int productTypeId);
  static QSqlQuery sameProductsJoinProductTypes(int productTypeId);
  static QSqlQuery productsJoinProductTypes();

public:
  static int productTypeId(int productId);

public:
  template <typename T, typename Container = std::vector<T>>
  static QSqlQuery selectOrderBy(const QString &tableName,
                                 const Container &args);
  QSqlQuery selectOrderBy(TableType table, ColumnType column);
  QSqlQuery selectOrderBy(TableType table, ColumnType column1,
                          ColumnType column2);
  static QSqlQuery select(TableType table);
  static QSqlQuery selectValue(int recordId, ColumnType columnId,
                               ColumnType columnValue, TableType table);
};

#endif // SQLSCRIPT_H
