/*
  Warnings:

  - The values [MEDICAL_RECORD,IMAGING] on the enum `DocumentType` will be removed. If these variants are still used in the database, this will fail.
  - You are about to drop the column `countryCode` on the `Patient` table. All the data in the column will be lost.
  - You are about to drop the column `nationality` on the `Patient` table. All the data in the column will be lost.
  - You are about to alter the column `email` on the `Patient` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(255)`.
  - You are about to alter the column `firstName` on the `Patient` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(100)`.
  - You are about to alter the column `lastName` on the `Patient` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(100)`.
  - You are about to alter the column `phone` on the `Patient` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(20)`.
  - You are about to alter the column `preferredLanguage` on the `Patient` table. The data in that column could be lost. The data in that column will be cast from `Text` to `VarChar(10)`.
  - You are about to drop the column `note` on the `Review` table. All the data in the column will be lost.
  - You are about to drop the column `result` on the `Review` table. All the data in the column will be lost.
  - You are about to drop the column `expertise` on the `Users` table. All the data in the column will be lost.
  - You are about to drop the column `firstName` on the `Users` table. All the data in the column will be lost.
  - You are about to drop the column `lastName` on the `Users` table. All the data in the column will be lost.
  - You are about to drop the column `position` on the `Users` table. All the data in the column will be lost.
  - You are about to drop the `Interaction` table. If the table is not empty, all the data it contains will be lost.
  - A unique constraint covering the columns `[pid]` on the table `Patient` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[nationalityCode]` on the table `Patient` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[passportCode,nationalityId]` on the table `Patient` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[phone]` on the table `Patient` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[email]` on the table `Patient` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[firstName,lastName,birthDate]` on the table `Patient` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[email]` on the table `Staff` will be added. If there are existing duplicate values, this will fail.
  - A unique constraint covering the columns `[slug]` on the table `Users` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `fileUrl` to the `Document` table without a default value. This is not possible if the table is not empty.
  - Made the column `filename` on table `Document` required. This step will fail if there are existing NULL values in that column.
  - Added the required column `fileKey` to the `Image` table without a default value. This is not possible if the table is not empty.
  - Added the required column `pid` to the `Patient` table without a default value. This is not possible if the table is not empty.
  - Changed the type of `role` on the `Staff` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.
  - Added the required column `slug` to the `Users` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "DocStatus" AS ENUM ('NEW', 'PENDING_SCAN', 'SAFE', 'INFECTED', 'INVALID');

-- CreateEnum
CREATE TYPE "Sex" AS ENUM ('male', 'female', 'other');

-- CreateEnum
CREATE TYPE "UploadStatus" AS ENUM ('PENDING', 'UPLOADING', 'UPLOADED', 'VERIFIED', 'FAILED', 'EXPIRED');

-- CreateEnum
CREATE TYPE "StaffRoles" AS ENUM ('developer', 'admin', 'doctor', 'coordinator');

-- CreateEnum
CREATE TYPE "StaffStatus" AS ENUM ('ACTIVE', 'WARNED', 'RESTRICTED', 'BANNED');

-- CreateEnum
CREATE TYPE "ViolationType" AS ENUM ('SPAM', 'RATE_LIMIT', 'CONTENT', 'ABUSE');

-- CreateEnum
CREATE TYPE "RestrictionType" AS ENUM ('TEMP', 'SHADOW', 'PERMANENT');

-- CreateEnum
CREATE TYPE "ConfigType" AS ENUM ('BOOLEAN', 'NUMBER', 'STRING', 'JSON', 'STRING_ARRAY');

-- CreateEnum
CREATE TYPE "AuditAction" AS ENUM ('CREATE', 'UPDATE', 'DELETE', 'READ');

-- AlterEnum
BEGIN;
CREATE TYPE "DocumentType_new" AS ENUM ('MEDICAL_IMAGE', 'LAB_RESULT', 'PRESCRIPTION', 'PASSPORT', 'NATIONAL_ID', 'OTHER', 'OTHER_FILE');
ALTER TABLE "Document" ALTER COLUMN "type" TYPE "DocumentType_new" USING ("type"::text::"DocumentType_new");
ALTER TYPE "DocumentType" RENAME TO "DocumentType_old";
ALTER TYPE "DocumentType_new" RENAME TO "DocumentType";
DROP TYPE "public"."DocumentType_old";
COMMIT;

-- DropForeignKey
ALTER TABLE "Interaction" DROP CONSTRAINT "Interaction_caseId_fkey";

-- DropForeignKey
ALTER TABLE "Interaction" DROP CONSTRAINT "Interaction_staffId_fkey";

-- AlterTable
ALTER TABLE "CaseStatusHistory" ALTER COLUMN "to" DROP NOT NULL;

-- AlterTable
ALTER TABLE "Document" ADD COLUMN     "checksum" TEXT,
ADD COLUMN     "fileUrl" TEXT NOT NULL,
ADD COLUMN     "is_deleted" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "status" "DocStatus" NOT NULL DEFAULT 'NEW',
ALTER COLUMN "filename" SET NOT NULL;

-- AlterTable
ALTER TABLE "Image" ADD COLUMN     "fileKey" TEXT NOT NULL,
ADD COLUMN     "fileUrl" TEXT;

-- AlterTable
ALTER TABLE "Patient" DROP COLUMN "countryCode",
DROP COLUMN "nationality",
ADD COLUMN     "address" VARCHAR(500),
ADD COLUMN     "birthDate" TIMESTAMP(3),
ADD COLUMN     "deletedAt" TIMESTAMP(3),
ADD COLUMN     "nationalityCode" CHAR(3),
ADD COLUMN     "nationalityId" INTEGER,
ADD COLUMN     "passportCode" VARCHAR(20),
ADD COLUMN     "pid" VARCHAR(10) NOT NULL,
ADD COLUMN     "postalCode" VARCHAR(20),
ADD COLUMN     "sex" "Sex",
ALTER COLUMN "email" SET DATA TYPE VARCHAR(255),
ALTER COLUMN "firstName" SET DATA TYPE VARCHAR(100),
ALTER COLUMN "lastName" SET DATA TYPE VARCHAR(100),
ALTER COLUMN "phone" SET DATA TYPE VARCHAR(20),
ALTER COLUMN "preferredLanguage" SET DATA TYPE VARCHAR(10);

-- AlterTable
ALTER TABLE "Review" DROP COLUMN "note",
DROP COLUMN "result",
ADD COLUMN     "deletedAt" TIMESTAMP(3);

-- AlterTable
ALTER TABLE "Staff" ADD COLUMN     "email" TEXT,
ADD COLUMN     "is_verified" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "resetPasswordExpires" TIMESTAMP(3),
ADD COLUMN     "resetPasswordToken" TEXT,
ADD COLUMN     "send_notif_with_email" BOOLEAN NOT NULL DEFAULT false,
ADD COLUMN     "status" "StaffStatus" NOT NULL DEFAULT 'ACTIVE',
ADD COLUMN     "strikes" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN     "trustScore" INTEGER NOT NULL DEFAULT 100,
DROP COLUMN "role",
ADD COLUMN     "role" "StaffRoles" NOT NULL;

-- AlterTable
ALTER TABLE "Users" DROP COLUMN "expertise",
DROP COLUMN "firstName",
DROP COLUMN "lastName",
DROP COLUMN "position",
ADD COLUMN     "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN     "expertiseId" INTEGER,
ADD COLUMN     "medicalNumber" TEXT,
ADD COLUMN     "slug" TEXT NOT NULL,
ADD COLUMN     "teamName" TEXT;

-- DropTable
DROP TABLE "Interaction";

-- CreateTable
CREATE TABLE "ReviewTranslation" (
    "id" SERIAL NOT NULL,
    "reviewId" TEXT NOT NULL,
    "lang_id" INTEGER,
    "note" TEXT,
    "result" TEXT,

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

-- CreateTable
CREATE TABLE "UploadSession" (
    "id" TEXT NOT NULL,
    "uploadKey" TEXT NOT NULL,
    "nonce" TEXT NOT NULL,
    "used" BOOLEAN NOT NULL DEFAULT false,
    "createdById" TEXT,
    "purpose" TEXT NOT NULL,
    "allowedTypes" TEXT,
    "maxSize" INTEGER,
    "status" TEXT NOT NULL DEFAULT 'PENDING',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "expiresAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "Violation" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "type" "ViolationType" NOT NULL,
    "severity" INTEGER NOT NULL,
    "reason" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Restriction" (
    "id" TEXT NOT NULL,
    "userId" TEXT NOT NULL,
    "type" "RestrictionType" NOT NULL,
    "expiresAt" TIMESTAMP(3),

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

-- CreateTable
CREATE TABLE "StaffTranslation" (
    "id" SERIAL NOT NULL,
    "staffId" TEXT NOT NULL,
    "lang_id" INTEGER,
    "displayName" TEXT,
    "position" TEXT,
    "description" TEXT,

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

-- CreateTable
CREATE TABLE "UserTranslation" (
    "id" SERIAL NOT NULL,
    "userId" INTEGER NOT NULL,
    "lang_id" INTEGER,
    "firstName" TEXT,
    "lastName" TEXT,
    "position" TEXT,

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

-- CreateTable
CREATE TABLE "Expertise" (
    "id" SERIAL NOT NULL,
    "slug" VARCHAR(100) NOT NULL,

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

-- CreateTable
CREATE TABLE "ExpertiseTranslation" (
    "id" SERIAL NOT NULL,
    "expertiseId" INTEGER NOT NULL,
    "lang_id" INTEGER,
    "displayName" TEXT,

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

-- CreateTable
CREATE TABLE "PanelConfig" (
    "id" TEXT NOT NULL,
    "key" TEXT NOT NULL,
    "value" TEXT NOT NULL,
    "type" "ConfigType" NOT NULL,
    "description" TEXT,
    "updatedAt" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Default" (
    "id" TEXT NOT NULL DEFAULT 'SITE_DEFAULTS',
    "email" TEXT NOT NULL,
    "hospitalPhone" TEXT NOT NULL,
    "logoUrl" TEXT,
    "mapAddress" TEXT NOT NULL,
    "instagramLink" TEXT,
    "linkedinLink" TEXT,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "DefaultTranslation" (
    "id" SERIAL NOT NULL,
    "defaultId" TEXT NOT NULL,
    "languageId" INTEGER NOT NULL,
    "address" TEXT NOT NULL,
    "underLogoText" TEXT,

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

-- CreateTable
CREATE TABLE "Page" (
    "id" SERIAL NOT NULL,
    "slug" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "PageBlock" (
    "id" SERIAL NOT NULL,
    "pageId" INTEGER NOT NULL,
    "type" TEXT NOT NULL,
    "sort" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "PageBlockTranslation" (
    "id" SERIAL NOT NULL,
    "blockId" INTEGER NOT NULL,
    "lang_id" INTEGER,
    "field" TEXT NOT NULL,
    "value" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "Language" (
    "id" SERIAL NOT NULL,
    "title" TEXT NOT NULL,
    "slug" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "RefreshToken" (
    "id" SERIAL NOT NULL,
    "token" TEXT NOT NULL,
    "staffId" TEXT NOT NULL,
    "expiresAt" TIMESTAMP(3) NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "Countries" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "callCode" TEXT NOT NULL,
    "coverId" INTEGER,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "AuditLog" (
    "id" SERIAL NOT NULL,
    "actorId" TEXT,
    "actorRole" "StaffRoles",
    "action" "AuditAction" NOT NULL,
    "entity" TEXT NOT NULL,
    "entityId" INTEGER,
    "before" JSONB,
    "after" JSONB,
    "ip" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "AccessLog" (
    "id" SERIAL NOT NULL,
    "userId" TEXT NOT NULL,
    "userRole" "StaffRoles" NOT NULL,
    "resource" TEXT NOT NULL,
    "resourceId" INTEGER,
    "reason" TEXT,
    "ip" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "DecisionLog" (
    "id" SERIAL NOT NULL,
    "decisionType" TEXT NOT NULL,
    "input" JSONB NOT NULL,
    "output" JSONB NOT NULL,
    "algorithmVersion" TEXT NOT NULL,
    "actorId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "TermsOfService" (
    "id" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "version" TEXT NOT NULL,
    "isActive" BOOLEAN NOT NULL DEFAULT true,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "TosAcceptanceLog" (
    "id" SERIAL NOT NULL,
    "userId" TEXT NOT NULL,
    "policyType" TEXT NOT NULL,
    "policyVersion" TEXT NOT NULL,
    "acceptedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "ip" TEXT,

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

-- CreateTable
CREATE TABLE "PrivacyPolicy" (
    "id" SERIAL NOT NULL,
    "content" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "MedicalPackage" (
    "id" SERIAL NOT NULL,
    "thumbnail_id" INTEGER,
    "icon" TEXT,
    "priority" INTEGER,
    "parent_id" INTEGER,

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

-- CreateTable
CREATE TABLE "MedicalPackagesTranslation" (
    "id" SERIAL NOT NULL,
    "title" VARCHAR(50) NOT NULL,
    "content" TEXT,
    "lang_id" INTEGER,
    "medicalPackageId" INTEGER,

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

-- CreateTable
CREATE TABLE "TransferPackage" (
    "id" SERIAL NOT NULL,
    "location" TEXT NOT NULL,
    "price" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "TransferPackageTranslations" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "lang_id" INTEGER,
    "transferPackageId" INTEGER,

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

-- CreateTable
CREATE TABLE "TransferTeam" (
    "id" SERIAL NOT NULL,

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

-- CreateTable
CREATE TABLE "TransferTeamTranslation" (
    "id" SERIAL NOT NULL,
    "lang_id" INTEGER,
    "transferTeamId" INTEGER,
    "name" VARCHAR(50) NOT NULL,
    "introduction" TEXT NOT NULL,
    "duties" TEXT NOT NULL,
    "services" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "_TransferPackageLocationImages" (
    "A" INTEGER NOT NULL,
    "B" INTEGER NOT NULL,

    CONSTRAINT "_TransferPackageLocationImages_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateTable
CREATE TABLE "_TransferPackageGalleryImages" (
    "A" INTEGER NOT NULL,
    "B" INTEGER NOT NULL,

    CONSTRAINT "_TransferPackageGalleryImages_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateTable
CREATE TABLE "_TransferPackageToTransferTeam" (
    "A" INTEGER NOT NULL,
    "B" INTEGER NOT NULL,

    CONSTRAINT "_TransferPackageToTransferTeam_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateTable
CREATE TABLE "_TransferTeamToUsers" (
    "A" INTEGER NOT NULL,
    "B" INTEGER NOT NULL,

    CONSTRAINT "_TransferTeamToUsers_AB_pkey" PRIMARY KEY ("A","B")
);

-- CreateIndex
CREATE UNIQUE INDEX "ReviewTranslation_reviewId_lang_id_key" ON "ReviewTranslation"("reviewId", "lang_id");

-- CreateIndex
CREATE UNIQUE INDEX "UploadSession_uploadKey_key" ON "UploadSession"("uploadKey");

-- CreateIndex
CREATE UNIQUE INDEX "UploadSession_nonce_key" ON "UploadSession"("nonce");

-- CreateIndex
CREATE INDEX "UploadSession_createdById_idx" ON "UploadSession"("createdById");

-- CreateIndex
CREATE INDEX "UploadSession_status_idx" ON "UploadSession"("status");

-- CreateIndex
CREATE UNIQUE INDEX "StaffTranslation_staffId_lang_id_key" ON "StaffTranslation"("staffId", "lang_id");

-- CreateIndex
CREATE UNIQUE INDEX "UserTranslation_userId_lang_id_key" ON "UserTranslation"("userId", "lang_id");

-- CreateIndex
CREATE UNIQUE INDEX "ExpertiseTranslation_expertiseId_lang_id_key" ON "ExpertiseTranslation"("expertiseId", "lang_id");

-- CreateIndex
CREATE UNIQUE INDEX "PanelConfig_key_key" ON "PanelConfig"("key");

-- CreateIndex
CREATE UNIQUE INDEX "DefaultTranslation_defaultId_languageId_key" ON "DefaultTranslation"("defaultId", "languageId");

-- CreateIndex
CREATE UNIQUE INDEX "Page_slug_key" ON "Page"("slug");

-- CreateIndex
CREATE UNIQUE INDEX "Language_slug_key" ON "Language"("slug");

-- CreateIndex
CREATE INDEX "Language_id_slug_idx" ON "Language"("id", "slug");

-- CreateIndex
CREATE UNIQUE INDEX "RefreshToken_token_key" ON "RefreshToken"("token");

-- CreateIndex
CREATE INDEX "AuditLog_entity_entityId_idx" ON "AuditLog"("entity", "entityId");

-- CreateIndex
CREATE UNIQUE INDEX "TermsOfService_version_key" ON "TermsOfService"("version");

-- CreateIndex
CREATE UNIQUE INDEX "MedicalPackagesTranslation_medicalPackageId_lang_id_key" ON "MedicalPackagesTranslation"("medicalPackageId", "lang_id");

-- CreateIndex
CREATE UNIQUE INDEX "TransferPackageTranslations_transferPackageId_lang_id_key" ON "TransferPackageTranslations"("transferPackageId", "lang_id");

-- CreateIndex
CREATE UNIQUE INDEX "TransferTeamTranslation_transferTeamId_lang_id_key" ON "TransferTeamTranslation"("transferTeamId", "lang_id");

-- CreateIndex
CREATE INDEX "_TransferPackageLocationImages_B_index" ON "_TransferPackageLocationImages"("B");

-- CreateIndex
CREATE INDEX "_TransferPackageGalleryImages_B_index" ON "_TransferPackageGalleryImages"("B");

-- CreateIndex
CREATE INDEX "_TransferPackageToTransferTeam_B_index" ON "_TransferPackageToTransferTeam"("B");

-- CreateIndex
CREATE INDEX "_TransferTeamToUsers_B_index" ON "_TransferTeamToUsers"("B");

-- CreateIndex
CREATE INDEX "CaseStatusHistory_id_caseId_idx" ON "CaseStatusHistory"("id", "caseId");

-- CreateIndex
CREATE UNIQUE INDEX "Patient_pid_key" ON "Patient"("pid");

-- CreateIndex
CREATE INDEX "Patient_pid_idx" ON "Patient"("pid");

-- CreateIndex
CREATE UNIQUE INDEX "Patient_nationalityCode_key" ON "Patient"("nationalityCode");

-- CreateIndex
CREATE UNIQUE INDEX "Patient_passportCode_nationalityId_key" ON "Patient"("passportCode", "nationalityId");

-- CreateIndex
CREATE UNIQUE INDEX "Patient_phone_key" ON "Patient"("phone");

-- CreateIndex
CREATE UNIQUE INDEX "Patient_email_key" ON "Patient"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Patient_firstName_lastName_birthDate_key" ON "Patient"("firstName", "lastName", "birthDate");

-- CreateIndex
CREATE UNIQUE INDEX "Staff_email_key" ON "Staff"("email");

-- CreateIndex
CREATE UNIQUE INDEX "Users_slug_key" ON "Users"("slug");

-- CreateIndex
CREATE INDEX "Users_id_slug_idx" ON "Users"("id", "slug");

-- AddForeignKey
ALTER TABLE "Patient" ADD CONSTRAINT "Patient_nationalityId_fkey" FOREIGN KEY ("nationalityId") REFERENCES "Countries"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ReviewTranslation" ADD CONSTRAINT "ReviewTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ReviewTranslation" ADD CONSTRAINT "ReviewTranslation_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Violation" ADD CONSTRAINT "Violation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Staff"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Restriction" ADD CONSTRAINT "Restriction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Staff"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "StaffTranslation" ADD CONSTRAINT "StaffTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "StaffTranslation" ADD CONSTRAINT "StaffTranslation_staffId_fkey" FOREIGN KEY ("staffId") REFERENCES "Staff"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Users" ADD CONSTRAINT "Users_expertiseId_fkey" FOREIGN KEY ("expertiseId") REFERENCES "Expertise"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserTranslation" ADD CONSTRAINT "UserTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "UserTranslation" ADD CONSTRAINT "UserTranslation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExpertiseTranslation" ADD CONSTRAINT "ExpertiseTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "ExpertiseTranslation" ADD CONSTRAINT "ExpertiseTranslation_expertiseId_fkey" FOREIGN KEY ("expertiseId") REFERENCES "Expertise"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DefaultTranslation" ADD CONSTRAINT "DefaultTranslation_defaultId_fkey" FOREIGN KEY ("defaultId") REFERENCES "Default"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "DefaultTranslation" ADD CONSTRAINT "DefaultTranslation_languageId_fkey" FOREIGN KEY ("languageId") REFERENCES "Language"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PageBlock" ADD CONSTRAINT "PageBlock_pageId_fkey" FOREIGN KEY ("pageId") REFERENCES "Page"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PageBlockTranslation" ADD CONSTRAINT "PageBlockTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "PageBlockTranslation" ADD CONSTRAINT "PageBlockTranslation_blockId_fkey" FOREIGN KEY ("blockId") REFERENCES "PageBlock"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "RefreshToken" ADD CONSTRAINT "RefreshToken_staffId_fkey" FOREIGN KEY ("staffId") REFERENCES "Staff"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Countries" ADD CONSTRAINT "Countries_coverId_fkey" FOREIGN KEY ("coverId") REFERENCES "Image"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TosAcceptanceLog" ADD CONSTRAINT "TosAcceptanceLog_policyVersion_fkey" FOREIGN KEY ("policyVersion") REFERENCES "TermsOfService"("version") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MedicalPackage" ADD CONSTRAINT "MedicalPackage_thumbnail_id_fkey" FOREIGN KEY ("thumbnail_id") REFERENCES "Image"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MedicalPackage" ADD CONSTRAINT "MedicalPackage_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "MedicalPackage"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MedicalPackagesTranslation" ADD CONSTRAINT "MedicalPackagesTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "MedicalPackagesTranslation" ADD CONSTRAINT "MedicalPackagesTranslation_medicalPackageId_fkey" FOREIGN KEY ("medicalPackageId") REFERENCES "MedicalPackage"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TransferPackageTranslations" ADD CONSTRAINT "TransferPackageTranslations_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TransferPackageTranslations" ADD CONSTRAINT "TransferPackageTranslations_transferPackageId_fkey" FOREIGN KEY ("transferPackageId") REFERENCES "TransferPackage"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TransferTeamTranslation" ADD CONSTRAINT "TransferTeamTranslation_lang_id_fkey" FOREIGN KEY ("lang_id") REFERENCES "Language"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TransferTeamTranslation" ADD CONSTRAINT "TransferTeamTranslation_transferTeamId_fkey" FOREIGN KEY ("transferTeamId") REFERENCES "TransferTeam"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferPackageLocationImages" ADD CONSTRAINT "_TransferPackageLocationImages_A_fkey" FOREIGN KEY ("A") REFERENCES "Image"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferPackageLocationImages" ADD CONSTRAINT "_TransferPackageLocationImages_B_fkey" FOREIGN KEY ("B") REFERENCES "TransferPackage"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferPackageGalleryImages" ADD CONSTRAINT "_TransferPackageGalleryImages_A_fkey" FOREIGN KEY ("A") REFERENCES "Image"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferPackageGalleryImages" ADD CONSTRAINT "_TransferPackageGalleryImages_B_fkey" FOREIGN KEY ("B") REFERENCES "TransferPackage"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferPackageToTransferTeam" ADD CONSTRAINT "_TransferPackageToTransferTeam_A_fkey" FOREIGN KEY ("A") REFERENCES "TransferPackage"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferPackageToTransferTeam" ADD CONSTRAINT "_TransferPackageToTransferTeam_B_fkey" FOREIGN KEY ("B") REFERENCES "TransferTeam"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferTeamToUsers" ADD CONSTRAINT "_TransferTeamToUsers_A_fkey" FOREIGN KEY ("A") REFERENCES "TransferTeam"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_TransferTeamToUsers" ADD CONSTRAINT "_TransferTeamToUsers_B_fkey" FOREIGN KEY ("B") REFERENCES "Users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
