import { DataTypes } from 'sequelize';

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

export const up: Migration = async ({ context }) => {
  await context.createTable('payouts', models.Payout.GENESIS_ATTRIBUTES);
  await safeApplyColumnChanges(context, {
    payment_links: [
      {
        name: 'donation_settings',
        field: {
          type: DataTypes.JSON,
          allowNull: true,
        },
      },
    ],
    payment_intents: [
      {
        name: 'beneficiaries',
        field: {
          type: DataTypes.JSON,
          allowNull: true,
        },
      },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.dropTable('payouts');
  await context.removeColumn('payment_links', 'donation_settings');
  await context.removeColumn('payment_intents', 'beneficiaries');
};
