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(
        'countries',
        'name',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { transaction },
      );

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

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

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

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

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

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

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

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

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

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

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

      await queryInterface.addColumn(
        'clients',
        'countryId',
        {
          type: Sequelize.DataTypes.UUID,

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

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

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

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

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

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

      await queryInterface.addColumn(
        'clients',
        'account_managerId',
        {
          type: Sequelize.DataTypes.UUID,

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

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

      await queryInterface.addColumn(
        'clients',
        'inclusive_amends',
        {
          type: Sequelize.DataTypes.BOOLEAN,

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

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

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

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

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

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

      await queryInterface.addColumn(
        'clients',
        'xero_id',
        {
          type: Sequelize.DataTypes.TEXT,
        },
        { 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('clients', 'xero_id', { transaction });

      await queryInterface.removeColumn('clients', 'insurance_fee', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'production_fee', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'public_url', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'client_id_link', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'early_payment_discount', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'inclusive_amends', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'agency', { transaction });

      await queryInterface.removeColumn('clients', 'account_managerId', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'curious_customer_id', {
        transaction,
      });

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

      await queryInterface.removeColumn('clients', 'website', { transaction });

      await queryInterface.removeColumn('clients', 'phone_number', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'country_txt', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'countryId', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'post_code', {
        transaction,
      });

      await queryInterface.removeColumn('clients', 'city', { transaction });

      await queryInterface.removeColumn('clients', 'address', { transaction });

      await queryInterface.removeColumn('clients', 'office', { transaction });

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

      await queryInterface.removeColumn('clients', 'thyme_id', { transaction });

      await queryInterface.removeColumn('client_orders', 'order_number', {
        transaction,
      });

      await queryInterface.removeColumn('client_orders', 'order_name', {
        transaction,
      });

      await queryInterface.removeColumn('client_orders', 'status', {
        transaction,
      });

      await queryInterface.removeColumn('countries', 'default_prefill', {
        transaction,
      });

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

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

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