const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const Asset = sequelize.define('Asset', {
    id: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
    },
    symbol: {
      type: DataTypes.STRING(20),
      unique: true,
      allowNull: false,
    },
    name: {
      type: DataTypes.STRING(100),
      allowNull: false,
    },
    description: {
      type: DataTypes.TEXT,
    },
    type: {
      type: DataTypes.ENUM('crypto', 'fiat', 'stock', 'forex', 'commodity'),
      allowNull: false,
    },
    exchange: {
      type: DataTypes.STRING(100),
    },
    industry: {
      type: DataTypes.STRING(100),
    },
    logo: {
      type: DataTypes.STRING(500),
    },
    decimals: {
      type: DataTypes.INTEGER,
      defaultValue: 8,
    },
    coinMarketId: DataTypes.BIGINT.UNSIGNED,
    slug: DataTypes.STRING(100),
    // Trading Settings
    tradingEnabled: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      field: 'trading_enabled',
    },

    allowWallet: {
      type: DataTypes.BOOLEAN,
      defaultValue: true,
      field: 'allow_wallet',
    },
    
    // Status
    status: {
      type: DataTypes.ENUM('active', 'inactive', 'delisting'),
      defaultValue: 'active',
    },

   

    metadata: {
      type: DataTypes.JSON,
      defaultValue: {},
    },
  }, {
    tableName: 'assets',
    timestamps: true,
    underscored: true,
    indexes: [
      { fields: ['symbol'] },
      { fields: ['type'] },
      { fields: ['status'] },
      { fields: ['rank'] },
    ],
  });

  return Asset;
};
