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

module.exports = (sequelize) => {
    const CoinMarket = sequelize.define('CoinMarket', {
        id: {
            type: DataTypes.BIGINT.UNSIGNED,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
        },
        symbol:{
            type: DataTypes.STRING(20),
            unique: true,
            allowNull: false,
            references: {
                model: 'coin_markets',
                key: 'symbol'
            }
        },
        price:{
            type: DataTypes.DECIMAL(30, 8),
        },
        marketCap: {
            type: DataTypes.DECIMAL(30, 8),
            field: 'market_cap'
        },
        fullyDilutedValuation: {
            type: DataTypes.DECIMAL(30, 8),
            field: 'fully_diluted_valuation'
        },
        volume24h: {
            type: DataTypes.DECIMAL(30, 8),
        },
        circulatingSupply: {
            type: DataTypes.DECIMAL(30, 8),
            field: 'circulating_supply'
        },
        maxSupply: {
            type: DataTypes.DECIMAL(30, 8),
            field: 'max_supply'
        },
        change1h: {
            type: DataTypes.DECIMAL(30, 8),
            defaultValue: 8,
        },
        change7d: {
            type: DataTypes.DECIMAL(30, 8),
            defaultValue: 8,
        },
        change24h: {
            type: DataTypes.DECIMAL(30, 8),
            defaultValue: 8,
        },

    }, {
        tableName: 'coin_markets',
        timestamps: true,
        underscored: true,
        indexes: [
            { fields: ['symbol'] },

        ],
    });

    return CoinMarket;
};
