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

export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
  await db.execute(sql`
   CREATE TYPE "public"."enum_parish_blocks_title_color" AS ENUM('base', 'shade1', 'shade2', 'shade3', 'contrast', 'contrastShade1');
  CREATE TYPE "public"."enum__parish_v_blocks_title_color" AS ENUM('base', 'shade1', 'shade2', 'shade3', 'contrast', 'contrastShade1');
  CREATE TYPE "public"."enum_pages_blocks_title_color" AS ENUM('base', 'shade1', 'shade2', 'shade3', 'contrast', 'contrastShade1');
  CREATE TYPE "public"."enum__pages_v_blocks_title_color" AS ENUM('base', 'shade1', 'shade2', 'shade3', 'contrast', 'contrastShade1');
  ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-04-12T12:46:39.042Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-04-12T12:46:39.348Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-05-10T12:46:39.403Z';
  ALTER TABLE "parish_blocks_title" ADD COLUMN "color" "enum_parish_blocks_title_color" DEFAULT 'base';
  ALTER TABLE "_parish_v_blocks_title" ADD COLUMN "color" "enum__parish_v_blocks_title_color" DEFAULT 'base';
  ALTER TABLE "pages_blocks_title" ADD COLUMN "color" "enum_pages_blocks_title_color" DEFAULT 'base';
  ALTER TABLE "_pages_v_blocks_title" ADD COLUMN "color" "enum__pages_v_blocks_title_color" DEFAULT 'base';`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-04-12T11:52:47.682Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-04-12T11:52:47.973Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-05-10T11:52:48.026Z';
  ALTER TABLE "parish_blocks_title" DROP COLUMN "color";
  ALTER TABLE "_parish_v_blocks_title" DROP COLUMN "color";
  ALTER TABLE "pages_blocks_title" DROP COLUMN "color";
  ALTER TABLE "_pages_v_blocks_title" DROP COLUMN "color";
  DROP TYPE "public"."enum_parish_blocks_title_color";
  DROP TYPE "public"."enum__parish_v_blocks_title_color";
  DROP TYPE "public"."enum_pages_blocks_title_color";
  DROP TYPE "public"."enum__pages_v_blocks_title_color";`)
}
