import { DataTypes } from 'sequelize';

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

export const up: Migration = async ({ context }) => {
  await safeApplyColumnChanges(context, {
    customers: [
      {
        name: 'overdraft_protection',
        field: {
          type: DataTypes.JSON,
          defaultValue: JSON.stringify({
            status: 'inactive',
            remaining_quantity: 0,
            total: 0,
          }),
        },
      },
    ],
  });
};

export const down: Migration = async ({ context }) => {
  await context.removeColumn('customers', 'overdraft_protection');
};
