module.exports = {
  /**
   * @param {QueryInterface} queryInterface
   * @param {Sequelize} Sequelize
   * @returns {Promise<void>}
   */
  async up(queryInterface, Sequelize) {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.addColumn(
        'businesses',
        'google_place_id',
        {
          type: Sequelize.DataTypes.TEXT,
          allowNull: true,
        },
        { transaction }
      );
      await queryInterface.addColumn(
        'businesses',
        'is_claimed',
        {
          type: Sequelize.DataTypes.BOOLEAN,
          defaultValue: false,
          allowNull: false,
        },
        { transaction }
      );
      await queryInterface.addColumn(
        'businesses',
        'rating',
        {
          type: Sequelize.DataTypes.DECIMAL(3, 2),
          defaultValue: 0,
          allowNull: false,
        },
        { transaction }
      );
      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  },

  /**
   * @param {QueryInterface} queryInterface
   * @param {Sequelize} Sequelize
   * @returns {Promise<void>}
   */
  async down(queryInterface, Sequelize) {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.removeColumn('businesses', 'google_place_id', { transaction });
      await queryInterface.removeColumn('businesses', 'is_claimed', { transaction });
      await queryInterface.removeColumn('businesses', 'rating', { transaction });
      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  }
};
