/* eslint-disable no-await-in-loop */
import { DataTypes } from 'sequelize';

import { Migration, safeApplyColumnChanges } from '../migrate';

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    products: [{ name: 'cross_sell', field: { type: DataTypes.JSON, allowNull: true } }],
    checkout_sessions: [
      { name: 'cross_sell_behavior', field: { type: DataTypes.ENUM('auto', 'required'), defaultValue: 'auto' } },
    ],
    payment_links: [
      { name: 'cross_sell_behavior', field: { type: DataTypes.ENUM('auto', 'required'), defaultValue: 'auto' } },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('products', 'cross_sell');
  await context.removeColumn('checkout_sessions', 'cross_sell_behavior');
  await context.removeColumn('payment_links', 'cross_sell_behavior');
};
