import type { Migration } from '../migrate';
import models from '../models';

export const up: Migration = async ({ context }) => {
  await context.createTable('checkout_sessions', models.CheckoutSession.GENESIS_ATTRIBUTES);
  await context.createTable('coupons', models.Coupon.GENESIS_ATTRIBUTES);
  await context.createTable('customers', models.Customer.GENESIS_ATTRIBUTES);
  await context.createTable('discounts', models.Discount.GENESIS_ATTRIBUTES);
  await context.createTable('events', models.Event.GENESIS_ATTRIBUTES);
  await context.createTable('invoices', models.Invoice.GENESIS_ATTRIBUTES);
  await context.createTable('invoice_items', models.InvoiceItem.GENESIS_ATTRIBUTES);
  await context.createTable('jobs', models.Job.GENESIS_ATTRIBUTES);
  await context.createTable('payment_currencies', models.PaymentCurrency.GENESIS_ATTRIBUTES);
  await context.createTable('payment_intents', models.PaymentIntent.GENESIS_ATTRIBUTES);
  await context.createTable('payment_links', models.PaymentLink.GENESIS_ATTRIBUTES);
  await context.createTable('payment_methods', models.PaymentMethod.GENESIS_ATTRIBUTES);
  await context.createTable('prices', models.Price.GENESIS_ATTRIBUTES);
  await context.createTable('products', models.Product.GENESIS_ATTRIBUTES);
  await context.createTable('promotion_codes', models.PromotionCode.GENESIS_ATTRIBUTES);
  await context.createTable('setup_intents', models.SetupIntent.GENESIS_ATTRIBUTES);
  await context.createTable('subscription_items', models.SubscriptionItem.GENESIS_ATTRIBUTES);
  await context.createTable('subscription_schedules', models.SubscriptionSchedule.GENESIS_ATTRIBUTES);
  await context.createTable('subscriptions', models.Subscription.GENESIS_ATTRIBUTES);
  await context.createTable('usage_records', models.UsageRecord.GENESIS_ATTRIBUTES);
  await context.createTable('webhook_attempts', models.WebhookAttempt.GENESIS_ATTRIBUTES);
  await context.createTable('webhook_endpoints', models.WebhookEndpoint.GENESIS_ATTRIBUTES);
};

export const down: Migration = async ({ context }) => {
  await context.dropTable('checkout_sessions');
  await context.dropTable('coupons');
  await context.dropTable('customers');
  await context.dropTable('discounts');
  await context.dropTable('events');
  await context.dropTable('invoices');
  await context.dropTable('invoice_items');
  await context.dropTable('jobs');
  await context.dropTable('payment_currencies');
  await context.dropTable('payment_intents');
  await context.dropTable('payment_links');
  await context.dropTable('payment_methods');
  await context.dropTable('prices');
  await context.dropTable('products');
  await context.dropTable('promotion_codes');
  await context.dropTable('setup_intents');
  await context.dropTable('subscription_items');
  await context.dropTable('subscription_schedules');
  await context.dropTable('subscriptions');
  await context.dropTable('usage_records');
  await context.dropTable('webhook_endpoints');
  await context.dropTable('webhook_attempts');
};
