const { DataTypes } = require("sequelize");

module.exports = (sequelize) => {
  const WalletLedger = sequelize.define(
    "WalletLedger",
    {
      userId: { type: DataTypes.INTEGER, allowNull: false },

      walletType: {
        type: DataTypes.ENUM("real", "demo"),
        allowNull: false,
        defaultValue: "demo",
      },

      tradeId: { type: DataTypes.INTEGER, allowNull: true },

      type: {
        type: DataTypes.ENUM("trade_debit", "trade_credit", "refund", "adjustment"),
        allowNull: false,
      },

      amount: { type: DataTypes.DECIMAL(18, 4), allowNull: false },
      balanceBefore: { type: DataTypes.DECIMAL(18, 4), allowNull: false },
      balanceAfter: { type: DataTypes.DECIMAL(18, 4), allowNull: false },

      note: { type: DataTypes.STRING, allowNull: true },
    },
    {
      tableName: "wallet_ledger",
      underscored: true,
      timestamps: true,
    }
  );

  return WalletLedger;
};