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_pages_blocks_mass_times_range" AS ENUM('rolling', 'week');
  CREATE TYPE "public"."enum__pages_v_blocks_mass_times_range" AS ENUM('rolling', 'week');
  ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-07-26T09:04:34.613Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-07-26T09:04:34.950Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-08-20T09:04:35.030Z';
  ALTER TABLE "pages_blocks_mass_times" ADD COLUMN "range" "enum_pages_blocks_mass_times_range" DEFAULT 'rolling';
  ALTER TABLE "_pages_v_blocks_mass_times" ADD COLUMN "range" "enum__pages_v_blocks_mass_times_range" DEFAULT 'rolling';`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-07-19T11:32:04.857Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-07-19T11:32:05.134Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-08-15T11:32:05.193Z';
  ALTER TABLE "pages_blocks_mass_times" DROP COLUMN "range";
  ALTER TABLE "_pages_v_blocks_mass_times" DROP COLUMN "range";
  DROP TYPE "public"."enum_pages_blocks_mass_times_range";
  DROP TYPE "public"."enum__pages_v_blocks_mass_times_range";`)
}
