-- CreateEnum
CREATE TYPE "ContentStatus" AS ENUM ('DRAFT', 'PUBLISHED');

-- CreateEnum
CREATE TYPE "Difficulty" AS ENUM ('BEGINNER', 'INTERMEDIATE', 'ADVANCED', 'EXPERT');

-- CreateEnum
CREATE TYPE "InteractionType" AS ENUM ('LIKE', 'SHARE', 'BOOKMARK', 'COMMENT');

-- CreateTable
CREATE TABLE "Project" (
    "id" SERIAL NOT NULL,
    "slug" VARCHAR(255) NOT NULL,
    "defaultLocale" VARCHAR(10) NOT NULL DEFAULT 'en',
    "title" VARCHAR(255) NOT NULL,
    "description" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "tags" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "featured" BOOLEAN NOT NULL DEFAULT false,
    "category" VARCHAR(100) NOT NULL,
    "date" VARCHAR(10) NOT NULL,
    "github" VARCHAR(500),
    "live" VARCHAR(500),
    "published" BOOLEAN NOT NULL DEFAULT true,
    "imageUrl" VARCHAR(500),
    "metaDescription" TEXT,
    "keywords" TEXT,
    "ogImage" VARCHAR(500),
    "schema" JSONB,
    "difficulty" "Difficulty" NOT NULL DEFAULT 'INTERMEDIATE',
    "timeToComplete" VARCHAR(100),
    "technologies" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "challenges" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "lessonsLearned" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "futureImprovements" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "demoVideo" VARCHAR(500),
    "screenshots" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "colorScheme" VARCHAR(100) NOT NULL DEFAULT 'Dark',
    "accessibility" BOOLEAN NOT NULL DEFAULT true,
    "performance" JSONB NOT NULL DEFAULT '{"loadTime": "1.5s", "bundleSize": "50KB", "lighthouse": 90}',
    "analytics" JSONB NOT NULL DEFAULT '{"likes": 0, "views": 0, "shares": 0}',
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Project_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "project_translations" (
    "id" SERIAL NOT NULL,
    "project_id" INTEGER NOT NULL,
    "locale" VARCHAR(10) NOT NULL,
    "title" VARCHAR(255) NOT NULL,
    "description" TEXT NOT NULL,
    "content" JSONB,
    "metaDescription" TEXT,
    "keywords" TEXT,
    "ogImage" VARCHAR(500),
    "schema" JSONB,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "project_translations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "content_pages" (
    "id" SERIAL NOT NULL,
    "key" VARCHAR(100) NOT NULL,
    "status" "ContentStatus" NOT NULL DEFAULT 'PUBLISHED',
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "content_pages_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "content_page_translations" (
    "id" SERIAL NOT NULL,
    "page_id" INTEGER NOT NULL,
    "locale" VARCHAR(10) NOT NULL,
    "title" TEXT,
    "slug" VARCHAR(255),
    "content" JSONB NOT NULL,
    "metaDescription" TEXT,
    "keywords" TEXT,
    "updated_at" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "content_page_translations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "site_settings" (
    "id" INTEGER NOT NULL DEFAULT 1,
    "defaultLocale" VARCHAR(10) NOT NULL DEFAULT 'en',
    "locales" TEXT[] DEFAULT ARRAY['en', 'de']::TEXT[],
    "theme" JSONB,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "site_settings_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "PageView" (
    "id" SERIAL NOT NULL,
    "project_id" INTEGER,
    "page" VARCHAR(100) NOT NULL,
    "ip" VARCHAR(45),
    "user_agent" TEXT,
    "referrer" VARCHAR(500),
    "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "PageView_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "UserInteraction" (
    "id" SERIAL NOT NULL,
    "project_id" INTEGER NOT NULL,
    "type" "InteractionType" NOT NULL,
    "ip" VARCHAR(45),
    "user_agent" TEXT,
    "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "UserInteraction_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Contact" (
    "id" SERIAL NOT NULL,
    "name" VARCHAR(255) NOT NULL,
    "email" VARCHAR(255) NOT NULL,
    "subject" VARCHAR(500) NOT NULL,
    "message" TEXT NOT NULL,
    "responded" BOOLEAN NOT NULL DEFAULT false,
    "response_template" VARCHAR(50),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "Contact_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "activity_status" (
    "id" INTEGER NOT NULL DEFAULT 1,
    "activity_type" VARCHAR(50),
    "activity_details" VARCHAR(255),
    "activity_project" VARCHAR(255),
    "activity_language" VARCHAR(50),
    "activity_repo" VARCHAR(500),
    "music_playing" BOOLEAN NOT NULL DEFAULT false,
    "music_track" VARCHAR(255),
    "music_artist" VARCHAR(255),
    "music_album" VARCHAR(255),
    "music_platform" VARCHAR(50),
    "music_progress" INTEGER,
    "music_album_art" VARCHAR(500),
    "watching_title" VARCHAR(255),
    "watching_platform" VARCHAR(50),
    "watching_type" VARCHAR(50),
    "gaming_game" VARCHAR(255),
    "gaming_platform" VARCHAR(50),
    "gaming_status" VARCHAR(50),
    "status_mood" VARCHAR(50),
    "status_message" VARCHAR(500),
    "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

    CONSTRAINT "activity_status_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Project_slug_key" ON "Project"("slug");

-- CreateIndex
CREATE INDEX "Project_category_idx" ON "Project"("category");

-- CreateIndex
CREATE INDEX "Project_featured_idx" ON "Project"("featured");

-- CreateIndex
CREATE INDEX "Project_published_idx" ON "Project"("published");

-- CreateIndex
CREATE INDEX "Project_difficulty_idx" ON "Project"("difficulty");

-- CreateIndex
CREATE INDEX "Project_created_at_idx" ON "Project"("created_at");

-- CreateIndex
CREATE INDEX "Project_tags_idx" ON "Project"("tags");

-- CreateIndex
CREATE INDEX "project_translations_locale_idx" ON "project_translations"("locale");

-- CreateIndex
CREATE INDEX "project_translations_project_id_idx" ON "project_translations"("project_id");

-- CreateIndex
CREATE UNIQUE INDEX "project_translations_project_id_locale_key" ON "project_translations"("project_id", "locale");

-- CreateIndex
CREATE UNIQUE INDEX "content_pages_key_key" ON "content_pages"("key");

-- CreateIndex
CREATE INDEX "content_page_translations_locale_idx" ON "content_page_translations"("locale");

-- CreateIndex
CREATE INDEX "content_page_translations_slug_idx" ON "content_page_translations"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "content_page_translations_page_id_locale_key" ON "content_page_translations"("page_id", "locale");

-- CreateIndex
CREATE INDEX "PageView_project_id_idx" ON "PageView"("project_id");

-- CreateIndex
CREATE INDEX "PageView_timestamp_idx" ON "PageView"("timestamp");

-- CreateIndex
CREATE INDEX "PageView_page_idx" ON "PageView"("page");

-- CreateIndex
CREATE INDEX "UserInteraction_project_id_idx" ON "UserInteraction"("project_id");

-- CreateIndex
CREATE INDEX "UserInteraction_type_idx" ON "UserInteraction"("type");

-- CreateIndex
CREATE INDEX "UserInteraction_timestamp_idx" ON "UserInteraction"("timestamp");

-- CreateIndex
CREATE INDEX "Contact_email_idx" ON "Contact"("email");

-- CreateIndex
CREATE INDEX "Contact_responded_idx" ON "Contact"("responded");

-- CreateIndex
CREATE INDEX "Contact_created_at_idx" ON "Contact"("created_at");

-- AddForeignKey
ALTER TABLE "project_translations" ADD CONSTRAINT "project_translations_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "Project"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "content_page_translations" ADD CONSTRAINT "content_page_translations_page_id_fkey" FOREIGN KEY ("page_id") REFERENCES "content_pages"("id") ON DELETE CASCADE ON UPDATE CASCADE;

