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

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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    payment_links: [{ name: 'nft_mint_settings', field: { type: DataTypes.JSON, allowNull: true } }],
    checkout_sessions: [
      { name: 'nft_mint_settings', field: { type: DataTypes.JSON, allowNull: true } },
      { name: 'payment_intent_data', field: { type: DataTypes.JSON, allowNull: true } },
      { name: 'nft_mint_details', field: { type: DataTypes.JSON, allowNull: true } },
      {
        name: 'nft_mint_status',
        field: {
          type: DataTypes.ENUM('disabled', 'pending', 'minted', 'sent', 'error'),
          defaultValue: 'disabled',
          allowNull: false,
        },
      },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('payment_links', 'nft_mint_settings');
  await context.removeColumn('checkout_sessions', 'payment_intent_data');
  await context.removeColumn('checkout_sessions', 'nft_mint_settings');
  await context.removeColumn('checkout_sessions', 'nft_mint_details');
  await context.removeColumn('checkout_sessions', 'nft_mint_status');
};
