"use strict";

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // Add paymentFailedNotifiedAt - tracks when owner notified renter about failed payment
    await queryInterface.addColumn("Rentals", "paymentFailedNotifiedAt", {
      type: Sequelize.DATE,
      allowNull: true,
    });

    // Add paymentMethodUpdatedAt - tracks last payment method update for rate limiting
    await queryInterface.addColumn("Rentals", "paymentMethodUpdatedAt", {
      type: Sequelize.DATE,
      allowNull: true,
    });

    // Add paymentMethodUpdateCount - count of updates within time window for rate limiting
    await queryInterface.addColumn("Rentals", "paymentMethodUpdateCount", {
      type: Sequelize.INTEGER,
      allowNull: true,
      defaultValue: 0,
    });
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.removeColumn("Rentals", "paymentMethodUpdateCount");
    await queryInterface.removeColumn("Rentals", "paymentMethodUpdatedAt");
    await queryInterface.removeColumn("Rentals", "paymentFailedNotifiedAt");
  },
};
