const { Sequelize, DataTypes } = require('sequelize');

const { DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD } = process.env;

const sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASSWORD, {
  host: DB_HOST,
  port: DB_PORT,
  dialect: 'mysql',
});

const Order = sequelize.define(
  'Orders',
  {
    order_id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
    invoice_id: { type: DataTypes.STRING, allowNull: false },
    username: { type: DataTypes.STRING, allowNull: false },
    custom_id: { type: DataTypes.STRING, allowNull: false },
    amount: { type: DataTypes.STRING, allowNull: false },
    total_price: { type: DataTypes.DECIMAL, allowNull: false },
    currency_code: { type: DataTypes.STRING, allowNull: false },
    items: { type: DataTypes.STRING, allowNull: false },
    order_status: { type: DataTypes.STRING, allowNull: false, defaultValue: 'NOT_PAID' },
    salt: { type: DataTypes.STRING, allowNull: false },
  },
  { timestamps: true },
);

export { Order, sequelize };
