"use strict";

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 1. Rename price to monthlyPrice
    await queryInterface.renameColumn("SubscriptionPlans", "price", "monthlyPrice");

    // 2. Remove billingInterval
    await queryInterface.removeColumn("SubscriptionPlans", "billingInterval");

    // 3. Add annualDiscountPercentage
    await queryInterface.addColumn("SubscriptionPlans", "annualDiscountPercentage", {
      type: Sequelize.DECIMAL(5, 2),
      defaultValue: 0.00,
      comment: "Percentage discount applied if billed annually (e.g. 10.00 = 10%)",
    });
  },

  down: async (queryInterface, Sequelize) => {
    // 1. Remove annualDiscountPercentage
    await queryInterface.removeColumn("SubscriptionPlans", "annualDiscountPercentage");

    // 2. Add billingInterval back
    await queryInterface.addColumn("SubscriptionPlans", "billingInterval", {
      type: Sequelize.ENUM("monthly", "yearly"),
      allowNull: false,
      defaultValue: "monthly",
    });

    // 3. Rename monthlyPrice back to price
    await queryInterface.renameColumn("SubscriptionPlans", "monthlyPrice", "price");
  },
};
