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

      timeframe: { type: DataTypes.ENUM("1m","5m","15m","1h","4h","1d","1w"), allowNull: false },
      ts: { type: DataTypes.DATE, allowNull: false },

      open: { type: DataTypes.DECIMAL(30, 12), allowNull: false },
      high: { type: DataTypes.DECIMAL(30, 12), allowNull: false },
      low:  { type: DataTypes.DECIMAL(30, 12), allowNull: false },
      close:{ type: DataTypes.DECIMAL(30, 12), allowNull: false },
      volume:{ type: DataTypes.DECIMAL(30, 12), allowNull: false, defaultValue: 0 },
    },
    {
      tableName: "market_candles",
      underscored: true,
      timestamps: true,
      indexes: [
        { unique: true, fields: ["market_id", "timeframe", "ts"] },
        { fields: ["market_id", "timeframe", "ts"] },
      ],
    }
  );
};