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

export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "tenants" ADD COLUMN "email_from_address" varchar;
  ALTER TABLE "tenants" ADD COLUMN "email_from_name" varchar;
  ALTER TABLE "tenants" ADD COLUMN "email_reply_to" varchar;
  ALTER TABLE "tenants" ADD COLUMN "email_use_custom_smtp" boolean DEFAULT false;
  ALTER TABLE "tenants" ADD COLUMN "email_smtp_host" varchar;
  ALTER TABLE "tenants" ADD COLUMN "email_smtp_port" numeric DEFAULT 587;
  ALTER TABLE "tenants" ADD COLUMN "email_smtp_secure" boolean DEFAULT false;
  ALTER TABLE "tenants" ADD COLUMN "email_smtp_user" varchar;
  ALTER TABLE "tenants" ADD COLUMN "email_smtp_pass" varchar;`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "tenants" DROP COLUMN "email_from_address";
  ALTER TABLE "tenants" DROP COLUMN "email_from_name";
  ALTER TABLE "tenants" DROP COLUMN "email_reply_to";
  ALTER TABLE "tenants" DROP COLUMN "email_use_custom_smtp";
  ALTER TABLE "tenants" DROP COLUMN "email_smtp_host";
  ALTER TABLE "tenants" DROP COLUMN "email_smtp_port";
  ALTER TABLE "tenants" DROP COLUMN "email_smtp_secure";
  ALTER TABLE "tenants" DROP COLUMN "email_smtp_user";
  ALTER TABLE "tenants" DROP COLUMN "email_smtp_pass";`)
}
