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

const Candle1h = sequelize.define('Candle1h', {
  id: {
    type: DataTypes.BIGINT,
    primaryKey: true,
    autoIncrement: true
  },
  symbolId: {
    type: DataTypes.INTEGER,
    field: 'symbol_id',
    allowNull: false,
    references: {
      model: Symbol,
      key: 'id'
    }
  },
  openTime: {
    type: DataTypes.DATE,
    field: 'open_time',
    allowNull: false
  },
  closeTime: {
    type: DataTypes.DATE,
    field: 'close_time',
    allowNull: false
  },
  open: {
    type: DataTypes.DECIMAL(18, 8),
    allowNull: false
  },
  high: {
    type: DataTypes.DECIMAL(18, 8),
    allowNull: false
  },
  low: {
    type: DataTypes.DECIMAL(18, 8),
    allowNull: false
  },
  close: {
    type: DataTypes.DECIMAL(18, 8),
    allowNull: false
  },
  volume: {
    type: DataTypes.DECIMAL(20, 8)
  },
  tradesCount: {
    type: DataTypes.INTEGER,
    field: 'trades_count'
  },
  quoteVolume: {
    type: DataTypes.DECIMAL(20, 8),
    field: 'quote_volume'
  },
  createdAt: {
    type: DataTypes.DATE,
    field: 'created_at'
  }
}, {
  tableName: 'candles_1h',
  indexes: [
    { unique: true, fields: ['symbol_id', 'open_time'] },
    { fields: ['open_time'] }
  ]
});


module.exports = Candle1h;
