import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'

/**
 * Live support (Chatwoot) replaces the scripted help bubble.
 *
 * Three columns on `settings`, not on `settings_locales`: an address, a token and a switch are the same
 * in both languages. The old bubble's columns are deliberately left alone — they hold answers the academy
 * wrote, and the group is only hidden from use, not dropped.
 */
export async function up({ db }: MigrateUpArgs): Promise<void> {
  await db.execute(sql`
  ALTER TABLE "settings" ADD COLUMN "support_enabled" boolean DEFAULT false;
  ALTER TABLE "settings" ADD COLUMN "support_base_url" varchar;
  ALTER TABLE "settings" ADD COLUMN "support_website_token" varchar;`)
}

export async function down({ db }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
  ALTER TABLE "settings" DROP COLUMN "support_enabled";
  ALTER TABLE "settings" DROP COLUMN "support_base_url";
  ALTER TABLE "settings" DROP COLUMN "support_website_token";`)
}
