const {DataTypes} = require("sequelize")

module.exports = (sequelize) => {
  return sequelize.define(
    "SpotTrade",
    {
      id: { type: DataTypes.BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true },
      market_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },

      maker_order_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },
      taker_order_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },

      price: { type: DataTypes.DECIMAL(30, 12), allowNull: false },
      qty: { type: DataTypes.DECIMAL(30, 12), allowNull: false },

      maker_user_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },
      taker_user_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },

      fee_asset_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: true },
      maker_fee: { type: DataTypes.DECIMAL(30, 12), allowNull: false, defaultValue: 0 },
      taker_fee: { type: DataTypes.DECIMAL(30, 12), allowNull: false, defaultValue: 0 },
    },
    {
      tableName: "spot_trades",
      underscored: true,
      timestamps: true,
      indexes: [
        { fields: ["market_id", "created_at"] },
        { fields: ["maker_user_id", "created_at"] },
        { fields: ["taker_user_id", "created_at"] },
      ],
    }
  );
};