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

export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2025-09-21T07:52:17.724Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2025-09-21T07:52:17.817Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2025-10-15T07:52:17.878Z';
  ALTER TABLE "media" ADD COLUMN "copyrights_source" varchar DEFAULT '' NOT NULL;
  ALTER TABLE "media" ADD COLUMN "copyrights_public_without_name" boolean DEFAULT false NOT NULL;
  ALTER TABLE "media" ADD COLUMN "copyrights_consent" boolean DEFAULT false NOT NULL;
  UPDATE "media" SET copyrights_public_without_name = true, copyrights_consent = true;
`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
   ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2025-09-14T07:56:02.742Z';
  ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2025-09-14T07:56:02.825Z';
  ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2025-10-09T07:56:02.879Z';
  ALTER TABLE "media" DROP COLUMN "copyrights_source";
  ALTER TABLE "media" DROP COLUMN "copyrights_public_without_name";
  ALTER TABLE "media" DROP COLUMN "copyrights_consent";`)
}
