module.exports = {
  /**
   * @param {QueryInterface} queryInterface
   * @param {Sequelize} Sequelize
   * @returns {Promise<void>}
   */
  async up(queryInterface, Sequelize) {
    /**
     * @type {Transaction}
     */
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.addColumn(
        'default_activities_products',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'rate_type',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'standard_service',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'departmentId',
        {
          type: Sequelize.DataTypes.UUID,

          references: {
            model: 'departments',
            key: 'id',
          },
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'service_text',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'rate',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'service_id',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'service_code',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'unit_type',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'cost',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'qty',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'currency',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'rate_gbp',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'rate_eur',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'rate_usd',
        {
          type: Sequelize.DataTypes.DECIMAL,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'yes_fixed_text',
        {
          type: Sequelize.DataTypes.BOOLEAN,

          defaultValue: false,
          allowNull: false,
        },
        { transaction },
      );

      await queryInterface.addColumn(
        'default_activities_products',
        'no_fixed_text',
        {
          type: Sequelize.DataTypes.BOOLEAN,

          defaultValue: false,
          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) {
    /**
     * @type {Transaction}
     */
    const transaction = await queryInterface.sequelize.transaction();
    try {
      await queryInterface.removeColumn(
        'default_activities_products',
        'no_fixed_text',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'yes_fixed_text',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'rate_usd',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'rate_eur',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'rate_gbp',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'currency',
        { transaction },
      );

      await queryInterface.removeColumn('default_activities_products', 'qty', {
        transaction,
      });

      await queryInterface.removeColumn('default_activities_products', 'cost', {
        transaction,
      });

      await queryInterface.removeColumn(
        'default_activities_products',
        'unit_type',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'service_code',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'service_id',
        { transaction },
      );

      await queryInterface.removeColumn('default_activities_products', 'rate', {
        transaction,
      });

      await queryInterface.removeColumn(
        'default_activities_products',
        'service_text',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'departmentId',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'standard_service',
        { transaction },
      );

      await queryInterface.removeColumn(
        'default_activities_products',
        'rate_type',
        { transaction },
      );

      await queryInterface.removeColumn('default_activities_products', 'name', {
        transaction,
      });

      await transaction.commit();
    } catch (err) {
      await transaction.rollback();
      throw err;
    }
  },
};
