-- CreateEnum
CREATE TYPE "Sex" AS ENUM ('F', 'M');

-- CreateEnum
CREATE TYPE "MaritalStatus" AS ENUM ('casatorit', 'necasatorit', 'divortat', 'vaduv');

-- CreateEnum
CREATE TYPE "EmployeeStatus" AS ENUM ('activ', 'concediat', 'suspendat');

-- CreateEnum
CREATE TYPE "DocumentType" AS ENUM ('buletin_de_identitate', 'pasaport');

-- CreateEnum
CREATE TYPE "FamilyMemberType" AS ENUM ('contact_principal', 'sot', 'sotie', 'mama', 'tata', 'copil');

-- CreateEnum
CREATE TYPE "StudyType" AS ENUM ('superioare', 'medii_de_specialitate', 'secundare_tehnice', 'medii');

-- CreateEnum
CREATE TYPE "StudyLevel" AS ENUM ('de_baza', 'postuniversitar');

-- CreateEnum
CREATE TYPE "PostUniversityType" AS ENUM ('masterat', 'rezidentiat', 'secundariat', 'altele');

-- CreateEnum
CREATE TYPE "DiplomaStatus" AS ENUM ('confirmata', 'neconfirmata');

-- CreateEnum
CREATE TYPE "QualificationCategory" AS ENUM ('fara', 'cat_II', 'cat_I', 'superioara');

-- CreateEnum
CREATE TYPE "ScientificTitle" AS ENUM ('doctor', 'doctor_habilitat');

-- CreateEnum
CREATE TYPE "TrainingType" AS ENUM ('orientare', 'intern', 'extern_RM', 'extern_international');

-- CreateEnum
CREATE TYPE "DisciplinarySanctionType" AS ENUM ('avertisment', 'mustrare', 'mustrare_aspra');

-- CreateEnum
CREATE TYPE "ContractPeriod" AS ENUM ('determinata', 'nedeterminata', 'replasare_temporara');

-- CreateEnum
CREATE TYPE "ContractCategory" AS ENUM ('principal', 'secundar');

-- CreateEnum
CREATE TYPE "ContractType" AS ENUM ('de_baza', 'cumul');

-- CreateEnum
CREATE TYPE "SalaryType" AS ENUM ('fix', 'pe_ore', 'in_acord');

-- CreateEnum
CREATE TYPE "CampaignStatus" AS ENUM ('draft', 'scheduled', 'in_progress', 'closed');

-- CreateEnum
CREATE TYPE "EvaluationScore" AS ENUM ('slab', 'mediu', 'bine');

-- CreateEnum
CREATE TYPE "ProposedCategory" AS ENUM ('fara', 'cat_II', 'cat_I', 'superioara');

-- CreateEnum
CREATE TYPE "MedicalCheckupType" AS ENUM ('la_angajare', 'periodic', 'la_reluarea_activitatii', 'la_incetarea_expunerii', 'suplimentar');

-- CreateEnum
CREATE TYPE "MedicalVerdict" AS ENUM ('apt', 'apt_perioada_adaptare', 'apt_conditionat', 'inapt_temporar', 'inapt');

-- CreateTable
CREATE TABLE "disability_grades" (
    "id" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "name" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "tax_exemptions" (
    "id" TEXT NOT NULL,
    "code" TEXT NOT NULL,
    "description" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "work_schedules" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "daysWork" INTEGER NOT NULL,
    "daysRest" INTEGER NOT NULL,
    "hoursPerDay" INTEGER NOT NULL,

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

-- CreateTable
CREATE TABLE "departments" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "code" TEXT,
    "parentId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "employees" (
    "id" TEXT NOT NULL,
    "idnp" VARCHAR(13) NOT NULL,
    "nume" TEXT NOT NULL,
    "prenume" TEXT NOT NULL,
    "patronimic" TEXT,
    "numeAnterior" TEXT,
    "dataNasterii" DATE NOT NULL,
    "domiciliu" TEXT NOT NULL,
    "adresaReala" TEXT,
    "telefonPersonal" TEXT NOT NULL,
    "telefonServiciu" TEXT,
    "emailPersonal" TEXT,
    "emailCorporativ" TEXT,
    "sex" "Sex" NOT NULL,
    "codCpas" TEXT,
    "stareCivila" "MaritalStatus",
    "titluStiintific" "ScientificTitle",
    "titluUniversitar" TEXT,
    "status" "EmployeeStatus" NOT NULL DEFAULT 'activ',
    "gradDizabilitateId" TEXT,
    "recomandareInternaId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "identity_documents" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "tipAct" "DocumentType" NOT NULL,
    "seria" TEXT,
    "nr" TEXT NOT NULL,
    "dataEmiterii" DATE NOT NULL,
    "autoritateEmitenta" TEXT NOT NULL,
    "dataExpirarii" DATE NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "family_members" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "tip" "FamilyMemberType" NOT NULL,
    "numePrenume" TEXT NOT NULL,
    "dataNasterii" DATE,
    "idnp" VARCHAR(13),
    "telefon" TEXT,
    "tipScutireId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "educations" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "tipStudii" "StudyType" NOT NULL,
    "institutia" TEXT NOT NULL,
    "specialitatea" TEXT NOT NULL,
    "dataAbsolvirii" DATE,
    "nrSeriaDiploma" TEXT,
    "dataEmiterii" DATE,
    "nrInregistrare" TEXT,
    "confirmare" "DiplomaStatus",
    "nivel" "StudyLevel",
    "tipPostuniversitar" "PostUniversityType",
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "qualifications" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "categorie" "QualificationCategory" NOT NULL,
    "dataObtinerii" DATE,
    "dataUltimeiConfirmari" DATE,
    "dataExpirarii" DATE,
    "specialitate" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "trainings" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "denumire" TEXT NOT NULL,
    "inceput" DATE NOT NULL,
    "sfirsit" DATE,
    "tip" "TrainingType" NOT NULL,
    "tara" TEXT,
    "nrOre" INTEGER,
    "organizatia" TEXT,
    "certificat" BOOLEAN NOT NULL DEFAULT false,
    "cost" DECIMAL(10,2),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "disciplinary_sanctions" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "tip" "DisciplinarySanctionType" NOT NULL,
    "dataAplicarii" DATE NOT NULL,
    "dataExpirarii" DATE NOT NULL,
    "isStinsa" BOOLEAN NOT NULL DEFAULT false,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "benefits" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "uniformaId" TEXT,
    "halatId" TEXT,
    "ciupiciId" TEXT,
    "vestaId" TEXT,
    "ticheteMasa" BOOLEAN NOT NULL DEFAULT false,
    "valoareTichet" DECIMAL(10,2),
    "alimentatiePersonal" BOOLEAN NOT NULL DEFAULT false,
    "abonamentTel" DECIMAL(10,2),
    "aparatTelefonId" TEXT,
    "cardCompanie" TEXT,
    "automobilServiciu" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "employment_contracts" (
    "id" TEXT NOT NULL,
    "nrCim" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "categorie" "ContractCategory" NOT NULL,
    "dataSemnarii" DATE NOT NULL,
    "dataAngajarii" DATE NOT NULL,
    "dataDemisiei" DATE,
    "perioada" "ContractPeriod" NOT NULL,
    "dataTerminarii" DATE,
    "functiaClasificator" TEXT,
    "codFunctie" TEXT,
    "functiaOrganigrama" TEXT,
    "tipCim" "ContractType" NOT NULL,
    "departmentId" TEXT NOT NULL,
    "regimMunca" TEXT,
    "tipSalarizare" "SalaryType",
    "salarizareDetails" JSONB,
    "clausaAditionala" JSONB,
    "workScheduleId" TEXT,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "cim_service_categories" (
    "id" TEXT NOT NULL,
    "contractId" TEXT NOT NULL,
    "categorieId" TEXT NOT NULL,
    "tipRemunerare" TEXT NOT NULL,
    "sumaNeta" DECIMAL(10,2),
    "procent" DECIMAL(5,2),

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

-- CreateTable
CREATE TABLE "evaluation_campaigns" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "departmentId" TEXT NOT NULL,
    "month" DATE NOT NULL,
    "status" "CampaignStatus" NOT NULL DEFAULT 'draft',
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "evaluation_forms" (
    "id" TEXT NOT NULL,
    "campaignId" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "abilitatiClinice" "EvaluationScore",
    "judecataClinica" "EvaluationScore",
    "manopere" "EvaluationScore",
    "gestionareaSarcinilor" "EvaluationScore",
    "constiintaProfesionala" "EvaluationScore",
    "atitudineaPacienti" "EvaluationScore",
    "atitudineaColegi" "EvaluationScore",
    "atitudineaPersonalNonMed" "EvaluationScore",
    "utilizareSmartphone" "EvaluationScore",
    "respectareaProgramului" "EvaluationScore",
    "respectareaDressCode" "EvaluationScore",
    "testJci" JSONB,
    "completareaDocMed" BOOLEAN,
    "perfectioneazaCunostinte" BOOLEAN,
    "membruComitetCalitate" BOOLEAN,
    "functieDeMonitor" BOOLEAN,
    "inlocuiesteSuperiorul" BOOLEAN,
    "categorieCalculata" "ProposedCategory",
    "categorieAprobata" "ProposedCategory",
    "observatii" TEXT,
    "completedAt" TIMESTAMP(3),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "workplace_risk_cards" (
    "id" TEXT NOT NULL,
    "name" TEXT NOT NULL,
    "riskFactors" JSONB NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "employee_medical_profiles" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "ocupatieCorm" TEXT,
    "workplaceRiskCardId" TEXT,
    "dataUltimControlMedical" DATE,
    "expusRadiatiiIonizante" BOOLEAN NOT NULL DEFAULT false,
    "dataIntrarii" DATE,
    "expunereAnterioaraPerioda" TEXT,
    "expunereAnterioaraAni" INTEGER,
    "dozaCumulataExternaMsv" DECIMAL(10,4),
    "dozaCumulataInternaMsv" DECIMAL(10,4),
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "medical_checkups" (
    "id" TEXT NOT NULL,
    "employeeId" TEXT NOT NULL,
    "tip" "MedicalCheckupType" NOT NULL,
    "dataPlanificata" DATE NOT NULL,
    "dataEfectuata" DATE,
    "verdict" "MedicalVerdict",
    "recomandari" TEXT,
    "documenteGenerate" JSONB,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "audit_logs" (
    "id" BIGSERIAL NOT NULL,
    "ts" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "userId" TEXT NOT NULL,
    "userRole" VARCHAR(50) NOT NULL,
    "ip" VARCHAR(45),
    "action" VARCHAR(20) NOT NULL,
    "entity" VARCHAR(50) NOT NULL,
    "entityId" VARCHAR(50) NOT NULL,
    "field" VARCHAR(100),
    "oldValue" TEXT,
    "newValue" TEXT,
    "reason" TEXT,

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

-- CreateIndex
CREATE UNIQUE INDEX "disability_grades_code_key" ON "disability_grades"("code");

-- CreateIndex
CREATE UNIQUE INDEX "tax_exemptions_code_key" ON "tax_exemptions"("code");

-- CreateIndex
CREATE UNIQUE INDEX "work_schedules_name_key" ON "work_schedules"("name");

-- CreateIndex
CREATE UNIQUE INDEX "departments_code_key" ON "departments"("code");

-- CreateIndex
CREATE INDEX "departments_parentId_idx" ON "departments"("parentId");

-- CreateIndex
CREATE UNIQUE INDEX "employees_idnp_key" ON "employees"("idnp");

-- CreateIndex
CREATE INDEX "employees_idnp_idx" ON "employees"("idnp");

-- CreateIndex
CREATE INDEX "employees_nume_prenume_idx" ON "employees"("nume", "prenume");

-- CreateIndex
CREATE INDEX "employees_status_idx" ON "employees"("status");

-- CreateIndex
CREATE INDEX "employees_dataNasterii_idx" ON "employees"("dataNasterii");

-- CreateIndex
CREATE INDEX "identity_documents_employeeId_idx" ON "identity_documents"("employeeId");

-- CreateIndex
CREATE INDEX "identity_documents_dataExpirarii_idx" ON "identity_documents"("dataExpirarii");

-- CreateIndex
CREATE INDEX "family_members_employeeId_idx" ON "family_members"("employeeId");

-- CreateIndex
CREATE INDEX "educations_employeeId_idx" ON "educations"("employeeId");

-- CreateIndex
CREATE INDEX "qualifications_employeeId_idx" ON "qualifications"("employeeId");

-- CreateIndex
CREATE INDEX "qualifications_dataExpirarii_idx" ON "qualifications"("dataExpirarii");

-- CreateIndex
CREATE INDEX "trainings_employeeId_idx" ON "trainings"("employeeId");

-- CreateIndex
CREATE INDEX "disciplinary_sanctions_employeeId_idx" ON "disciplinary_sanctions"("employeeId");

-- CreateIndex
CREATE INDEX "disciplinary_sanctions_dataExpirarii_idx" ON "disciplinary_sanctions"("dataExpirarii");

-- CreateIndex
CREATE UNIQUE INDEX "benefits_employeeId_key" ON "benefits"("employeeId");

-- CreateIndex
CREATE UNIQUE INDEX "employment_contracts_nrCim_key" ON "employment_contracts"("nrCim");

-- CreateIndex
CREATE INDEX "employment_contracts_employeeId_idx" ON "employment_contracts"("employeeId");

-- CreateIndex
CREATE INDEX "employment_contracts_departmentId_idx" ON "employment_contracts"("departmentId");

-- CreateIndex
CREATE INDEX "employment_contracts_dataDemisiei_idx" ON "employment_contracts"("dataDemisiei");

-- CreateIndex
CREATE INDEX "cim_service_categories_contractId_idx" ON "cim_service_categories"("contractId");

-- CreateIndex
CREATE INDEX "evaluation_campaigns_departmentId_idx" ON "evaluation_campaigns"("departmentId");

-- CreateIndex
CREATE INDEX "evaluation_campaigns_month_idx" ON "evaluation_campaigns"("month");

-- CreateIndex
CREATE INDEX "evaluation_forms_campaignId_idx" ON "evaluation_forms"("campaignId");

-- CreateIndex
CREATE INDEX "evaluation_forms_employeeId_idx" ON "evaluation_forms"("employeeId");

-- CreateIndex
CREATE UNIQUE INDEX "evaluation_forms_campaignId_employeeId_key" ON "evaluation_forms"("campaignId", "employeeId");

-- CreateIndex
CREATE UNIQUE INDEX "workplace_risk_cards_name_key" ON "workplace_risk_cards"("name");

-- CreateIndex
CREATE UNIQUE INDEX "employee_medical_profiles_employeeId_key" ON "employee_medical_profiles"("employeeId");

-- CreateIndex
CREATE INDEX "medical_checkups_employeeId_idx" ON "medical_checkups"("employeeId");

-- CreateIndex
CREATE INDEX "medical_checkups_dataPlanificata_idx" ON "medical_checkups"("dataPlanificata");

-- CreateIndex
CREATE INDEX "audit_logs_userId_idx" ON "audit_logs"("userId");

-- CreateIndex
CREATE INDEX "audit_logs_entity_entityId_idx" ON "audit_logs"("entity", "entityId");

-- CreateIndex
CREATE INDEX "audit_logs_ts_idx" ON "audit_logs"("ts");

-- AddForeignKey
ALTER TABLE "departments" ADD CONSTRAINT "departments_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "departments"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employees" ADD CONSTRAINT "employees_gradDizabilitateId_fkey" FOREIGN KEY ("gradDizabilitateId") REFERENCES "disability_grades"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employees" ADD CONSTRAINT "employees_recomandareInternaId_fkey" FOREIGN KEY ("recomandareInternaId") REFERENCES "employees"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "identity_documents" ADD CONSTRAINT "identity_documents_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "family_members" ADD CONSTRAINT "family_members_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "family_members" ADD CONSTRAINT "family_members_tipScutireId_fkey" FOREIGN KEY ("tipScutireId") REFERENCES "tax_exemptions"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "educations" ADD CONSTRAINT "educations_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "qualifications" ADD CONSTRAINT "qualifications_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "trainings" ADD CONSTRAINT "trainings_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "disciplinary_sanctions" ADD CONSTRAINT "disciplinary_sanctions_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "benefits" ADD CONSTRAINT "benefits_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employment_contracts" ADD CONSTRAINT "employment_contracts_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employment_contracts" ADD CONSTRAINT "employment_contracts_departmentId_fkey" FOREIGN KEY ("departmentId") REFERENCES "departments"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employment_contracts" ADD CONSTRAINT "employment_contracts_workScheduleId_fkey" FOREIGN KEY ("workScheduleId") REFERENCES "work_schedules"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "cim_service_categories" ADD CONSTRAINT "cim_service_categories_contractId_fkey" FOREIGN KEY ("contractId") REFERENCES "employment_contracts"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "evaluation_campaigns" ADD CONSTRAINT "evaluation_campaigns_departmentId_fkey" FOREIGN KEY ("departmentId") REFERENCES "departments"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "evaluation_forms" ADD CONSTRAINT "evaluation_forms_campaignId_fkey" FOREIGN KEY ("campaignId") REFERENCES "evaluation_campaigns"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "evaluation_forms" ADD CONSTRAINT "evaluation_forms_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employee_medical_profiles" ADD CONSTRAINT "employee_medical_profiles_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "employee_medical_profiles" ADD CONSTRAINT "employee_medical_profiles_workplaceRiskCardId_fkey" FOREIGN KEY ("workplaceRiskCardId") REFERENCES "workplace_risk_cards"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "medical_checkups" ADD CONSTRAINT "medical_checkups_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "employees"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
