module.exports = {
  /**
   * @param {QueryInterface} queryInterface
   * @returns {Promise<void>}
   */
  async up(queryInterface) {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.createTable('funding_opportunities', {
        id: {
          type: queryInterface.sequelize.Sequelize.DataTypes.UUID,
          defaultValue: queryInterface.sequelize.Sequelize.DataTypes.UUIDV4,
          primaryKey: true,
        },
        name: {
          type: queryInterface.sequelize.Sequelize.DataTypes.TEXT,
        },
        focus: {
          type: queryInterface.sequelize.Sequelize.DataTypes.TEXT,
        },
        stage: {
          type: queryInterface.sequelize.Sequelize.DataTypes.TEXT,
        },
        contact_type: {
          type: queryInterface.sequelize.Sequelize.DataTypes.TEXT,
        },
        description: {
          type: queryInterface.sequelize.Sequelize.DataTypes.TEXT,
        },
        website: {
          type: queryInterface.sequelize.Sequelize.DataTypes.TEXT,
        },
        amount_min: {
          type: queryInterface.sequelize.Sequelize.DataTypes.DECIMAL,
        },
        amount_max: {
          type: queryInterface.sequelize.Sequelize.DataTypes.DECIMAL,
        },
        createdById: {
          type: queryInterface.sequelize.Sequelize.DataTypes.UUID,
          references: {
            key: 'id',
            model: 'users',
          },
        },
        updatedById: {
          type: queryInterface.sequelize.Sequelize.DataTypes.UUID,
          references: {
            key: 'id',
            model: 'users',
          },
        },
        createdAt: { type: queryInterface.sequelize.Sequelize.DataTypes.DATE },
        updatedAt: { type: queryInterface.sequelize.Sequelize.DataTypes.DATE },
        deletedAt: { type: queryInterface.sequelize.Sequelize.DataTypes.DATE },
        importHash: {
          type: queryInterface.sequelize.Sequelize.DataTypes.STRING(255),
          allowNull: true,
          unique: true,
        },
      }, { transaction });
      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  },

  async down(queryInterface) {
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.dropTable('funding_opportunities', { transaction });
      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  }
};