'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // Remove old columns if needed
    await queryInterface.removeColumn('CalendarEvents', 'date');
    await queryInterface.removeColumn('CalendarEvents', 'description');
    await queryInterface.removeColumn('CalendarEvents', 'link');

    // Add new columns
    await queryInterface.addColumn('CalendarEvents', 'startDate', {
      type: Sequelize.DATEONLY,
      allowNull: false
    });

    await queryInterface.addColumn('CalendarEvents', 'endDate', {
      type: Sequelize.DATEONLY,
      allowNull: false
    });

    await queryInterface.addColumn('CalendarEvents', 'type', {
      type: Sequelize.STRING,
      allowNull: false
    });
  },

  down: async (queryInterface, Sequelize) => {
    // Rollback logic
    await queryInterface.removeColumn('CalendarEvents', 'startDate');
    await queryInterface.removeColumn('CalendarEvents', 'endDate');
    await queryInterface.removeColumn('CalendarEvents', 'type');

    await queryInterface.addColumn('CalendarEvents', 'date', {
      type: Sequelize.DATEONLY,
      allowNull: false
    });

    await queryInterface.addColumn('CalendarEvents', 'description', {
      type: Sequelize.TEXT,
      allowNull: true
    });

    await queryInterface.addColumn('CalendarEvents', 'link', {
      type: Sequelize.STRING,
      allowNull: true
    });
  }
};
