-- CreateTable: expert_profiles
CREATE TABLE "expert_profiles" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "user_id" UUID NOT NULL,
    "skills" TEXT[] DEFAULT ARRAY[]::TEXT[],
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable: expert_experiences
CREATE TABLE "expert_experiences" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "expert_profile_id" UUID NOT NULL,
    "area" VARCHAR(200) NOT NULL,
    "years" INTEGER NOT NULL,
    "level" VARCHAR(50),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable: expert_languages
CREATE TABLE "expert_languages" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "expert_profile_id" UUID NOT NULL,
    "language" VARCHAR(100) NOT NULL,
    "level" VARCHAR(20) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable: expert_projects
CREATE TABLE "expert_projects" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "expert_profile_id" UUID NOT NULL,
    "from_month" INTEGER NOT NULL,
    "from_year" INTEGER NOT NULL,
    "to_month" INTEGER,
    "to_year" INTEGER,
    "is_current" BOOLEAN NOT NULL DEFAULT false,
    "role" VARCHAR(200) NOT NULL,
    "tasks" TEXT,
    "company" VARCHAR(200),
    "company_size" VARCHAR(20),
    "industry" VARCHAR(200),
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable: expert_certifications
CREATE TABLE "expert_certifications" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "expert_profile_id" UUID NOT NULL,
    "title" VARCHAR(300) NOT NULL,
    "issuing_body" VARCHAR(300) NOT NULL,
    "website" VARCHAR(500),
    "issue_year" INTEGER NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMP(3) NOT NULL,

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

-- CreateTable: expert_attachments
CREATE TABLE "expert_attachments" (
    "id" UUID NOT NULL DEFAULT gen_random_uuid(),
    "expert_profile_id" UUID NOT NULL,
    "filename" VARCHAR(255) NOT NULL,
    "mimetype" VARCHAR(100) NOT NULL,
    "size" INTEGER NOT NULL,
    "data" TEXT NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE UNIQUE INDEX "expert_profiles_user_id_key" ON "expert_profiles"("user_id");

-- CreateIndex
CREATE INDEX "expert_projects_expert_profile_id_from_year_from_month_idx" ON "expert_projects"("expert_profile_id", "from_year", "from_month");

-- AddForeignKey
ALTER TABLE "expert_profiles" ADD CONSTRAINT "expert_profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "expert_experiences" ADD CONSTRAINT "expert_experiences_expert_profile_id_fkey" FOREIGN KEY ("expert_profile_id") REFERENCES "expert_profiles"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "expert_languages" ADD CONSTRAINT "expert_languages_expert_profile_id_fkey" FOREIGN KEY ("expert_profile_id") REFERENCES "expert_profiles"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "expert_projects" ADD CONSTRAINT "expert_projects_expert_profile_id_fkey" FOREIGN KEY ("expert_profile_id") REFERENCES "expert_profiles"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "expert_certifications" ADD CONSTRAINT "expert_certifications_expert_profile_id_fkey" FOREIGN KEY ("expert_profile_id") REFERENCES "expert_profiles"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "expert_attachments" ADD CONSTRAINT "expert_attachments_expert_profile_id_fkey" FOREIGN KEY ("expert_profile_id") REFERENCES "expert_profiles"("id") ON DELETE CASCADE ON UPDATE CASCADE;
