'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('SystemProfits', {
      id: {
        allowNull: false,
        primaryKey: true,
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4
      },
      amount: {
        type: Sequelize.DECIMAL(20, 2),
        allowNull: false
      },
      source: {
        type: Sequelize.ENUM('deposit_fee', 'payout_fee'),
        allowNull: false
      },
      transactionId: {
        type: Sequelize.STRING,
        allowNull: false
      },
      merchantId: {
        type: Sequelize.UUID,
        allowNull: false,
        references: { model: 'Merchants', key: 'id' },
        onUpdate: 'CASCADE',
        onDelete: 'CASCADE'
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });

    await queryInterface.addIndex('SystemProfits', ['merchantId']);
    await queryInterface.addIndex('SystemProfits', ['source']);
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('SystemProfits');
  }
};
