const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const Symbol = require('./Symbol');

const LivePrice = sequelize.define('LivePrice', {
  symbolId: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    field: 'symbol_id',
    references: {
      model: Symbol,
      key: 'id'
    }
  },
  price: {
    type: DataTypes.DECIMAL(18, 8),
    allowNull: false
  },
  bid: {
    type: DataTypes.DECIMAL(18, 8)
  },
  ask: {
    type: DataTypes.DECIMAL(18, 8)
  },
  bidSize: {
    type: DataTypes.DECIMAL(18, 8),
    field: 'bid_size'
  },
  askSize: {
    type: DataTypes.DECIMAL(18, 8),
    field: 'ask_size'
  },
  lastUpdated: {
    type: DataTypes.DATE,
    field: 'last_updated',
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'live_prices',
  indexes: [
    { fields: ['price'] }
  ]
});


module.exports = LivePrice;
