'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('Merchants', {
      id: {
        allowNull: false,
        primaryKey: true,
        type: Sequelize.UUID,
        defaultValue: Sequelize.UUIDV4
      },
      businessName: {
        type: Sequelize.STRING,
        allowNull: false
      },
      email: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true
      },
      password: {
        type: Sequelize.STRING,
        allowNull: false
      },
      publicKey: {
        type: Sequelize.STRING,
        allowNull: false,
        unique: true
      },
      privateKey: {
        type: Sequelize.STRING,
        allowNull: false
      },
      merchantAccountNumber: {
          type: Sequelize.STRING,
          allowNull: true,
          unique: true
      },
      webhookUrl: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      balance: {
        type: Sequelize.DECIMAL(20, 2),
        defaultValue: 0.00
      },
      status: {
        type: Sequelize.ENUM('active', 'inactive', 'suspended'),
        defaultValue: 'active'
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });

    // --- Performance Indexes ---
    await queryInterface.addIndex('Merchants', ['email']);
    await queryInterface.addIndex('Merchants', ['publicKey']);
    await queryInterface.addIndex('Merchants', ['merchantAccountNumber']);
  },

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