#ifndef DATABASEINFO_HPP
#define DATABASEINFO_HPP

#include "databaseinfo.h"

inline constexpr const char *DatabaseInfo::name(DatabaseInfo::Table table) {
  switch (table) {
  case Table::AdditionalVariables:
    return "additional_variables";
  case Table::Attributes:
    return "attributes";
  case Table::PriceHistoryRecords:
    return "price_history_records";
  case Table::ProductAttributes:
    return "product_attributes";
  case Table::ProductInflowRecords:
    return "product_inflow_records";
  case Table::ProductOutflowRecords:
    return "product_outflow_records";
  case Table::ProductTypes:
    return "product_types";
  case Table::ProductValues:
    return "product_values";
  case Table::ProductWriteOffRecords:
    return "product_write_off_records";
  case Table::Products:
    return "products";
  case Table::Suppliers:
    return "suppliers";
  case Table::WriteOffReasons:
    return "write_off_reasons";
  }
  return nullptr;
}

inline constexpr const char *DatabaseInfo::name(DatabaseInfo::View view) {
  switch (view) {
  case View::ProductProperties:
    return "product_properties";
  case View::AvailableProductTypes:
    return "available_product_types";
  }
  return nullptr;
}

inline constexpr const char *DatabaseInfo::name(DatabaseInfo::Column column) {
  switch (column) {
  case Column::AdditionalVariables_Id:
  case Column::Attributes_Id:
  case Column::PriceHistoryRecords_Id:
  case Column::ProductInflowRecords_Id:
  case Column::ProductOutflowRecords_Id:
  case Column::ProductTypes_Id:
  case Column::ProductValues_Id:
  case Column::ProductWriteOffRecords_Id:
  case Column::Products_Id:
  case Column::Suppliers_Id:
  case Column::WriteOffReasons_Id:
  case Column::AvailableProductTypes_Id:
    return "id";
  case Column::AdditionalVariables_Name:
  case Column::Attributes_Name:
  case Column::ProductTypes_Name:
  case Column::Products_Name:
  case Column::Suppliers_Name:
  case Column::ProductProperties_Name:
  case Column::AvailableProductTypes_Name:
    return "name";
  case Column::Products_Barcode:
  case Column::ProductInflowRecords_Barcode:
  case Column::ProductOutflowRecords_Barcode:
  case Column::ProductWriteOffRecords_Barcode:
  case Column::Products_ProductTypes_Barcode:
    return "barcode";
  case Column::WriteOffReasons_Name:
  case Column::AdditionalVariables_Value:
  case Column::ProductValues_Value:
  case Column::ProductProperties_Value:
    return "value";
  case Column::PriceHistoryRecords_ProductId:
  case Column::ProductAttributes_ProductId:
  case Column::ProductValues_ProductId:
  case Column::Products_ProductTypes_ProductId:
  case Column::ProductProperties_ProductId:
  case Column::ProductInflowRecords_ProductId:
  case Column::ProductOutflowRecords_ProductId:
  case Column::ProductWriteOffRecords_ProductId:
    return "product_id";
  case Column::Products_ProductTypeId:
  case Column::Products_ProductTypes_ProductTypeId:
    return "product_type_id";
  case Column::Products_ProductTypes_ProductName:
    return "product_name";
  case Column::Products_ProductTypes_ProductTypeName:
    return "product_type_name";
  case Column::PriceHistoryRecords_Datetime:
  case Column::ProductInflowRecords_Datetime:
  case Column::ProductOutflowRecords_Datetime:
  case Column::ProductWriteOffRecords_Datetime:
    return "datetime";
  case Column::PriceHistoryRecords_Price:
    return "price";
  case Column::ProductAttributes_AttributeId:
  case Column::ProductValues_AttributeId:
  case Column::ProductProperties_AttributeId:
    return "attribute_id";
  case Column::ProductInflowRecords_SupplierId:
    return "supplier_id";
  case Column::ProductInflowRecords_Count:
  case Column::ProductOutflowRecords_Count:
  case Column::ProductWriteOffRecords_Count:
    return "count";
  case Column::ProductInflowRecords_FullPrice:
    return "full_price";
  case Column::ProductTypes_ParentId:
  case Column::AvailableProductTypes_ParentId:
    return "parent_id";
  case Column::ProductWriteOffRecords_ReasonId:
    return "reason_id";
  case Column::Suppliers_Address:
    return "address";
  case Column::Suppliers_TelephoneNumber:
    return "telephone_number";
  }
  return nullptr;
}

inline constexpr unsigned
DatabaseInfo::ordinalNumber(DatabaseInfo::Column column) {
  switch (column) {
  case Column::AdditionalVariables_Id:
  case Column::Attributes_Id:
  case Column::PriceHistoryRecords_Id:
  case Column::ProductAttributes_ProductId:
  case Column::ProductInflowRecords_Id:
  case Column::ProductOutflowRecords_Id:
  case Column::ProductTypes_Id:
  case Column::ProductValues_Id:
  case Column::ProductWriteOffRecords_Id:
  case Column::Products_Id:
  case Column::Suppliers_Id:
  case Column::WriteOffReasons_Id:
  case Column::Products_ProductTypes_ProductId:
  case Column::ProductProperties_ProductId:
  case Column::AvailableProductTypes_Id:
    return 1;
  case Column::AdditionalVariables_Name:
  case Column::Attributes_Name:
  case Column::PriceHistoryRecords_ProductId:
  case Column::ProductAttributes_AttributeId:
  case Column::ProductTypes_ParentId:
  case Column::ProductValues_ProductId:
  case Column::Products_Name:
  case Column::Suppliers_Name:
  case Column::WriteOffReasons_Name:
  case Column::ProductProperties_AttributeId:
  case Column::ProductInflowRecords_ProductId:
  case Column::ProductOutflowRecords_ProductId:
  case Column::ProductWriteOffRecords_ProductId:
  case Column::Products_Barcode:
  case Column::Products_ProductTypes_Barcode:
  case Column::AvailableProductTypes_ParentId:
    return 2;
  case Column::AdditionalVariables_Value:
  case Column::PriceHistoryRecords_Datetime:
  case Column::ProductInflowRecords_SupplierId:
  case Column::ProductOutflowRecords_Count:
  case Column::ProductTypes_Name:
  case Column::ProductValues_AttributeId:
  case Column::ProductWriteOffRecords_ReasonId:
  case Column::Products_ProductTypeId:
  case Column::Suppliers_Address:
  case Column::ProductProperties_Name:
  case Column::ProductInflowRecords_Barcode:
  case Column::ProductOutflowRecords_Barcode:
  case Column::ProductWriteOffRecords_Barcode:
  case Column::Products_ProductTypes_ProductTypeId:
  case Column::AvailableProductTypes_Name:
    return 3;
  case Column::PriceHistoryRecords_Price:
  case Column::ProductInflowRecords_Count:
  case Column::ProductOutflowRecords_Datetime:
  case Column::ProductValues_Value:
  case Column::ProductWriteOffRecords_Count:
  case Column::Suppliers_TelephoneNumber:
  case Column::Products_ProductTypes_ProductName:
  case Column::ProductProperties_Value:
    return 4;
  case Column::ProductInflowRecords_FullPrice:
  case Column::ProductWriteOffRecords_Datetime:
  case Column::Products_ProductTypes_ProductTypeName:
    return 5;
  case Column::ProductInflowRecords_Datetime:
    return 6;
  }
  return 0;
}

inline constexpr unsigned
DatabaseInfo::indexNumber(DatabaseInfo::Column column) {
  return ordinalNumber(column) - 1;
}

#endif // DATABASEINFO_HPP
