'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.sequelize.transaction(async (transaction) => {
      await queryInterface.removeColumn('paymongo_methods', 'id', { transaction });
      await queryInterface.addColumn(
        'paymongo_methods',
        'id',
        {
          type: Sequelize.UUID,
          defaultValue: Sequelize.UUIDV4,
          primaryKey: true,
          allowNull: false,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'paymongo_methods',
        'type',
        {
          type: Sequelize.ENUM('payment', 'dob'),
          allowNull: false,
          defaultValue: 'payment',
        },
        { transaction },
      );
    });
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.sequelize.transaction(async (transaction) => {
      await queryInterface.removeColumn('paymongo_methods', 'type', { transaction });
      await queryInterface.removeColumn('paymongo_methods', 'id', { transaction });
      await queryInterface.addColumn(
        'paymongo_methods',
        'id',
        {
          type: Sequelize.INTEGER,
          autoIncrement: true,
          primaryKey: true,
          allowNull: false,
        },
        { transaction },
      );
    });
  },
};
