/* eslint-disable no-console */
import { createIndexIfNotExists, type Migration } from '../migrate';

export const up: Migration = async ({ context }) => {
  await createIndexIfNotExists(
    context,
    'meter_events',
    ['livemode', 'event_name', 'timestamp'],
    'idx_meter_events_livemode_event_timestamp'
  );

  await createIndexIfNotExists(
    context,
    'payment_currencies',
    ['is_base_currency', 'livemode'],
    'idx_payment_currencies_base_livemode'
  );

  await createIndexIfNotExists(context, 'jobs', ['queue', 'id'], 'idx_jobs_queue_id');
  await createIndexIfNotExists(
    context,
    'jobs',
    ['queue', 'cancelled', 'will_run_at', 'delay'],
    'idx_jobs_queue_cancelled_run_at_delay'
  );
};

export const down: Migration = async ({ context }) => {
  await context.removeIndex('meter_events', 'idx_meter_events_livemode_event_timestamp');
  await context.removeIndex('payment_currencies', 'idx_payment_currencies_base_livemode');
  await context.removeIndex('jobs', 'idx_jobs_queue_id');
  await context.removeIndex('jobs', 'idx_jobs_queue_cancelled_run_at_delay');
};
