const {DataTypes} = require("sequelize")

module.exports = (sequelize) => {
  return sequelize.define(
    "DerivativeTrade",
    {
      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: true },
      taker_order_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: true },
      price: { type: DataTypes.DECIMAL(30, 12), allowNull: false },
      qty: { type: DataTypes.DECIMAL(30, 12), allowNull: false },
      maker_account_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: true },
      taker_account_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: true },
      fee: { type: DataTypes.DECIMAL(30, 12), allowNull: false, defaultValue: 0 },
      fee_asset_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: true },
    },
    {
      tableName: "derivative_trades",
      underscored: true,
      timestamps: true,
      indexes: [
        { fields: ["market_id", "created_at"] },
        { fields: ["taker_account_id", "created_at"] },
      ],
    }
  );
};