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_hero_slider_block_slides_text_alignment" AS ENUM('left', 'center', 'right');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_slides_vertical_position" AS ENUM('top', 'center', 'bottom');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_slides_overlay_color" AS ENUM('dark', 'light', 'primary', 'gradient-bottom', 'gradient-top');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_slides_overlay_opacity" AS ENUM('20', '30', '40', '50', '60', '70', '80');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_slides_primary_cta_style" AS ENUM('primary', 'secondary', 'outline-white', 'outline-dark');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_slides_secondary_cta_style" AS ENUM('primary', 'secondary', 'outline-white', 'outline-dark', 'text');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_slides_text_color" AS ENUM('white', 'dark', 'primary');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_settings_animation" AS ENUM('fade', 'slide', 'zoom', 'flip', 'none');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_settings_animation_duration" AS ENUM('300', '500', '800', '1200');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_settings_autoplay_interval" AS ENUM('3000', '4000', '5000', '6000', '7000', '8000', '10000');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_arrows_style" AS ENUM('default', 'minimal', 'square', 'hover-only');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_arrows_position" AS ENUM('sides', 'bottom-left', 'bottom-right', 'bottom-center');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_dots_style" AS ENUM('dots', 'lines', 'numbers', 'thumbnails', 'progress');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_dots_position" AS ENUM('bottom-center', 'bottom-left', 'bottom-right', 'left', 'right');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_dots_color" AS ENUM('white', 'dark', 'primary');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_layout_height" AS ENUM('viewport', 'large', 'medium', 'small', 'compact', 'auto');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_layout_mobile_height" AS ENUM('same', 'viewport', 'large', 'medium', 'small', 'compact');
  CREATE TYPE "public"."enum_pages_blocks_hero_slider_block_layout_content_width" AS ENUM('container', 'narrow', 'wide', 'full');
  CREATE TABLE "pages_blocks_hero_slider_block_slides" (
  	"_order" integer NOT NULL,
  	"_parent_id" varchar NOT NULL,
  	"id" varchar PRIMARY KEY NOT NULL,
  	"background_image_id" integer NOT NULL,
  	"mobile_background_image_id" integer,
  	"text_alignment" "enum_pages_blocks_hero_slider_block_slides_text_alignment" DEFAULT 'center',
  	"vertical_position" "enum_pages_blocks_hero_slider_block_slides_vertical_position" DEFAULT 'center',
  	"overlay_enabled" boolean DEFAULT true,
  	"overlay_color" "enum_pages_blocks_hero_slider_block_slides_overlay_color" DEFAULT 'dark',
  	"overlay_opacity" "enum_pages_blocks_hero_slider_block_slides_overlay_opacity" DEFAULT '50',
  	"primary_cta_enabled" boolean DEFAULT true,
  	"primary_cta_link" varchar,
  	"primary_cta_style" "enum_pages_blocks_hero_slider_block_slides_primary_cta_style" DEFAULT 'primary',
  	"primary_cta_open_in_new_tab" boolean DEFAULT false,
  	"secondary_cta_enabled" boolean DEFAULT false,
  	"secondary_cta_link" varchar,
  	"secondary_cta_style" "enum_pages_blocks_hero_slider_block_slides_secondary_cta_style" DEFAULT 'outline-white',
  	"secondary_cta_open_in_new_tab" boolean DEFAULT false,
  	"text_color" "enum_pages_blocks_hero_slider_block_slides_text_color" DEFAULT 'white'
  );
  
  CREATE TABLE "pages_blocks_hero_slider_block_slides_locales" (
  	"headline" varchar NOT NULL,
  	"subline" varchar,
  	"primary_cta_text" varchar,
  	"secondary_cta_text" varchar,
  	"id" serial PRIMARY KEY NOT NULL,
  	"_locale" "_locales" NOT NULL,
  	"_parent_id" varchar NOT NULL
  );
  
  CREATE TABLE "pages_blocks_hero_slider_block" (
  	"_order" integer NOT NULL,
  	"_parent_id" integer NOT NULL,
  	"_path" text NOT NULL,
  	"id" varchar PRIMARY KEY NOT NULL,
  	"settings_animation" "enum_pages_blocks_hero_slider_block_settings_animation" DEFAULT 'fade',
  	"settings_animation_duration" "enum_pages_blocks_hero_slider_block_settings_animation_duration" DEFAULT '500',
  	"settings_autoplay_enabled" boolean DEFAULT true,
  	"settings_autoplay_interval" "enum_pages_blocks_hero_slider_block_settings_autoplay_interval" DEFAULT '5000',
  	"settings_autoplay_pause_on_hover" boolean DEFAULT true,
  	"settings_autoplay_pause_on_interaction" boolean DEFAULT true,
  	"settings_loop" boolean DEFAULT true,
  	"navigation_arrows_enabled" boolean DEFAULT true,
  	"navigation_arrows_style" "enum_pages_blocks_hero_slider_block_navigation_arrows_style" DEFAULT 'default',
  	"navigation_arrows_position" "enum_pages_blocks_hero_slider_block_navigation_arrows_position" DEFAULT 'sides',
  	"navigation_arrows_hide_on_mobile" boolean DEFAULT false,
  	"navigation_dots_enabled" boolean DEFAULT true,
  	"navigation_dots_style" "enum_pages_blocks_hero_slider_block_navigation_dots_style" DEFAULT 'dots',
  	"navigation_dots_position" "enum_pages_blocks_hero_slider_block_navigation_dots_position" DEFAULT 'bottom-center',
  	"navigation_dots_color" "enum_pages_blocks_hero_slider_block_navigation_dots_color" DEFAULT 'white',
  	"navigation_swipe" boolean DEFAULT true,
  	"navigation_keyboard" boolean DEFAULT true,
  	"layout_height" "enum_pages_blocks_hero_slider_block_layout_height" DEFAULT 'viewport',
  	"layout_mobile_height" "enum_pages_blocks_hero_slider_block_layout_mobile_height" DEFAULT 'viewport',
  	"layout_content_width" "enum_pages_blocks_hero_slider_block_layout_content_width" DEFAULT 'container',
  	"layout_full_width" boolean DEFAULT true,
  	"accessibility_reduced_motion" boolean DEFAULT true,
  	"block_name" varchar
  );
  
  CREATE TABLE "pages_blocks_hero_slider_block_locales" (
  	"accessibility_aria_label" varchar DEFAULT 'Hero Slider',
  	"id" serial PRIMARY KEY NOT NULL,
  	"_locale" "_locales" NOT NULL,
  	"_parent_id" varchar NOT NULL
  );
  
  ALTER TABLE "pages_blocks_hero_slider_block_slides" ADD CONSTRAINT "pages_blocks_hero_slider_block_slides_background_image_id_media_id_fk" FOREIGN KEY ("background_image_id") REFERENCES "public"."media"("id") ON DELETE set null ON UPDATE no action;
  ALTER TABLE "pages_blocks_hero_slider_block_slides" ADD CONSTRAINT "pages_blocks_hero_slider_block_slides_mobile_background_image_id_media_id_fk" FOREIGN KEY ("mobile_background_image_id") REFERENCES "public"."media"("id") ON DELETE set null ON UPDATE no action;
  ALTER TABLE "pages_blocks_hero_slider_block_slides" ADD CONSTRAINT "pages_blocks_hero_slider_block_slides_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."pages_blocks_hero_slider_block"("id") ON DELETE cascade ON UPDATE no action;
  ALTER TABLE "pages_blocks_hero_slider_block_slides_locales" ADD CONSTRAINT "pages_blocks_hero_slider_block_slides_locales_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."pages_blocks_hero_slider_block_slides"("id") ON DELETE cascade ON UPDATE no action;
  ALTER TABLE "pages_blocks_hero_slider_block" ADD CONSTRAINT "pages_blocks_hero_slider_block_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;
  ALTER TABLE "pages_blocks_hero_slider_block_locales" ADD CONSTRAINT "pages_blocks_hero_slider_block_locales_parent_id_fk" FOREIGN KEY ("_parent_id") REFERENCES "public"."pages_blocks_hero_slider_block"("id") ON DELETE cascade ON UPDATE no action;
  CREATE INDEX "pages_blocks_hero_slider_block_slides_order_idx" ON "pages_blocks_hero_slider_block_slides" USING btree ("_order");
  CREATE INDEX "pages_blocks_hero_slider_block_slides_parent_id_idx" ON "pages_blocks_hero_slider_block_slides" USING btree ("_parent_id");
  CREATE INDEX "pages_blocks_hero_slider_block_slides_background_image_idx" ON "pages_blocks_hero_slider_block_slides" USING btree ("background_image_id");
  CREATE INDEX "pages_blocks_hero_slider_block_slides_mobile_background__idx" ON "pages_blocks_hero_slider_block_slides" USING btree ("mobile_background_image_id");
  CREATE UNIQUE INDEX "pages_blocks_hero_slider_block_slides_locales_locale_parent_" ON "pages_blocks_hero_slider_block_slides_locales" USING btree ("_locale","_parent_id");
  CREATE INDEX "pages_blocks_hero_slider_block_order_idx" ON "pages_blocks_hero_slider_block" USING btree ("_order");
  CREATE INDEX "pages_blocks_hero_slider_block_parent_id_idx" ON "pages_blocks_hero_slider_block" USING btree ("_parent_id");
  CREATE INDEX "pages_blocks_hero_slider_block_path_idx" ON "pages_blocks_hero_slider_block" USING btree ("_path");
  CREATE UNIQUE INDEX "pages_blocks_hero_slider_block_locales_locale_parent_id_uniq" ON "pages_blocks_hero_slider_block_locales" USING btree ("_locale","_parent_id");`)
}

export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
  await db.execute(sql`
   DROP TABLE "pages_blocks_hero_slider_block_slides" CASCADE;
  DROP TABLE "pages_blocks_hero_slider_block_slides_locales" CASCADE;
  DROP TABLE "pages_blocks_hero_slider_block" CASCADE;
  DROP TABLE "pages_blocks_hero_slider_block_locales" CASCADE;
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_text_alignment";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_vertical_position";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_overlay_color";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_overlay_opacity";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_primary_cta_style";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_secondary_cta_style";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_slides_text_color";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_settings_animation";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_settings_animation_duration";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_settings_autoplay_interval";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_arrows_style";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_arrows_position";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_dots_style";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_dots_position";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_navigation_dots_color";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_layout_height";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_layout_mobile_height";
  DROP TYPE "public"."enum_pages_blocks_hero_slider_block_layout_content_width";`)
}
