-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "platform_performance";

-- CreateEnum
CREATE TYPE "platform_performance"."CycleType" AS ENUM ('MONTHLY', 'QUARTERLY', 'SEMI_ANNUAL', 'ANNUAL', 'CUSTOM');

-- CreateEnum
CREATE TYPE "platform_performance"."CycleStatus" AS ENUM ('DRAFT', 'GOAL_SETTING', 'IN_PROGRESS', 'EVALUATING', 'CALIBRATING', 'COMPLETED', 'ARCHIVED');

-- CreateEnum
CREATE TYPE "platform_performance"."ObjectiveLevel" AS ENUM ('COMPANY', 'DEPARTMENT', 'PERSONAL');

-- CreateEnum
CREATE TYPE "platform_performance"."ObjectiveStatus" AS ENUM ('DRAFT', 'PENDING_APPROVAL', 'REJECTED', 'IN_PROGRESS', 'EVALUATING', 'COMPLETED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "platform_performance"."MetricType" AS ENUM ('NUMBER', 'PERCENTAGE', 'MILESTONE');

-- CreateEnum
CREATE TYPE "platform_performance"."KpiAssessmentStatus" AS ENUM ('PENDING', 'SELF_EVALUATED', 'MANAGER_EVALUATED', 'CONFIRMED');

-- CreateEnum
CREATE TYPE "platform_performance"."Evaluation360Status" AS ENUM ('DRAFT', 'IN_PROGRESS', 'COLLECTING', 'COMPLETED', 'RELEASED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "platform_performance"."EvaluationTaskStatus" AS ENUM ('PENDING', 'SUBMITTED', 'EXPIRED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "platform_performance"."RelationType" AS ENUM ('SELF', 'SUPERVISOR', 'PEER', 'SUBORDINATE');

-- CreateEnum
CREATE TYPE "platform_performance"."CalibrationSessionStatus" AS ENUM ('SCHEDULED', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "platform_performance"."CalibrationRole" AS ENUM ('FACILITATOR', 'PARTICIPANT');

-- CreateEnum
CREATE TYPE "platform_performance"."InterviewType" AS ENUM ('REGULAR', 'IMPROVEMENT', 'DEVELOPMENT');

-- CreateEnum
CREATE TYPE "platform_performance"."InterviewStatus" AS ENUM ('SCHEDULED', 'PENDING_CONFIRMATION', 'COMPLETED', 'CANCELLED');

-- CreateEnum
CREATE TYPE "platform_performance"."PerformanceFeedbackType" AS ENUM ('PRAISE', 'SUGGESTION', 'QUESTION');

-- CreateTable
CREATE TABLE "platform_performance"."grade_config" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "grades" JSONB NOT NULL,
    "is_default" BOOLEAN NOT NULL DEFAULT false,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."performance_cycle" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "type" "platform_performance"."CycleType" NOT NULL,
    "status" "platform_performance"."CycleStatus" NOT NULL DEFAULT 'DRAFT',
    "start_date" DATE NOT NULL,
    "end_date" DATE NOT NULL,
    "goal_deadline" DATE,
    "execution_start_date" DATE,
    "evaluation_start_date" DATE,
    "template_id" UUID,
    "grade_config_id" UUID,
    "results_published_at" TIMESTAMPTZ(3),
    "results_published_by" UUID,
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."cycle_template" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "type" "platform_performance"."CycleType" NOT NULL,
    "duration_days" INTEGER NOT NULL,
    "goal_deadline_days" INTEGER,
    "evaluation_start_days" INTEGER,
    "default_assessment_template_id" UUID,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "platform_performance"."performance_result" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "employee_id" UUID NOT NULL,
    "okr_score" DECIMAL(5,2),
    "okr_weight" DECIMAL(5,2),
    "kpi_score" DECIMAL(5,2),
    "kpi_weight" DECIMAL(5,2),
    "e360_score" DECIMAL(5,2),
    "e360_weight" DECIMAL(5,2),
    "total_score" DECIMAL(5,2) NOT NULL,
    "grade_code" TEXT NOT NULL,
    "grade_name" TEXT NOT NULL,
    "is_published" BOOLEAN NOT NULL DEFAULT false,
    "published_at" TIMESTAMPTZ(3),
    "viewed_by_employee" BOOLEAN NOT NULL DEFAULT false,
    "viewed_at" TIMESTAMPTZ(3),
    "remarks" TEXT,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."objective" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "owner_id" UUID NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT,
    "level" "platform_performance"."ObjectiveLevel" NOT NULL,
    "status" "platform_performance"."ObjectiveStatus" NOT NULL DEFAULT 'DRAFT',
    "progress" DECIMAL(5,2) NOT NULL DEFAULT 0,
    "parent_id" UUID,
    "approver_id" UUID,
    "approved_at" TIMESTAMPTZ(3),
    "reject_reason" TEXT,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."key_result" (
    "id" UUID NOT NULL,
    "objective_id" UUID NOT NULL,
    "title" TEXT NOT NULL,
    "metric_type" "platform_performance"."MetricType" NOT NULL,
    "start_value" DECIMAL(10,2) NOT NULL,
    "target_value" DECIMAL(10,2) NOT NULL,
    "current_value" DECIMAL(10,2) NOT NULL DEFAULT 0,
    "progress" DECIMAL(5,2) NOT NULL DEFAULT 0,
    "weight" DECIMAL(5,2) NOT NULL,
    "unit" TEXT,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."kr_progress_history" (
    "id" UUID NOT NULL,
    "key_result_id" UUID NOT NULL,
    "value" DECIMAL(10,2) NOT NULL,
    "note" TEXT,
    "recorded_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "recorded_by" UUID NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."kpi_indicator" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "category" TEXT,
    "formula" TEXT,
    "data_source" TEXT,
    "min_weight" DECIMAL(5,2),
    "max_weight" DECIMAL(5,2),
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."kpi_assignment" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "employee_id" UUID NOT NULL,
    "indicator_id" UUID NOT NULL,
    "weight" DECIMAL(5,2) NOT NULL,
    "target_value" DECIMAL(10,2),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "platform_performance"."kpi_assessment" (
    "id" UUID NOT NULL,
    "assignment_id" UUID NOT NULL,
    "status" "platform_performance"."KpiAssessmentStatus" NOT NULL DEFAULT 'PENDING',
    "self_score" DECIMAL(5,2),
    "self_comment" TEXT,
    "self_evaluated_at" TIMESTAMPTZ(3),
    "manager_score" DECIMAL(5,2),
    "manager_comment" TEXT,
    "manager_id" UUID,
    "manager_evaluated_at" TIMESTAMPTZ(3),
    "final_score" DECIMAL(5,2),
    "proposed_grade_code" TEXT,
    "final_grade_code" TEXT,
    "grade_adjusted_by" UUID,
    "grade_adjusted_at" TIMESTAMPTZ(3),
    "grade_adjust_reason" TEXT,
    "confirmed_at" TIMESTAMPTZ(3),

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

-- CreateTable
CREATE TABLE "platform_performance"."evaluation_360" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "target_id" UUID NOT NULL,
    "status" "platform_performance"."Evaluation360Status" NOT NULL DEFAULT 'DRAFT',
    "template_id" UUID,
    "deadline" DATE NOT NULL,
    "min_evaluators" INTEGER,
    "released_at" TIMESTAMPTZ(3),
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."evaluation_task" (
    "id" UUID NOT NULL,
    "evaluation_id" UUID NOT NULL,
    "evaluator_id" UUID NOT NULL,
    "relation_type" "platform_performance"."RelationType" NOT NULL,
    "status" "platform_performance"."EvaluationTaskStatus" NOT NULL DEFAULT 'PENDING',
    "is_anonymous" BOOLEAN NOT NULL DEFAULT true,
    "submitted_at" TIMESTAMPTZ(3),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "platform_performance"."evaluation_response" (
    "id" UUID NOT NULL,
    "task_id" UUID NOT NULL,
    "dimension" TEXT NOT NULL,
    "score" DECIMAL(5,2) NOT NULL,
    "comment" TEXT,

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

-- CreateTable
CREATE TABLE "platform_performance"."assessment_template" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "dimensions" JSONB NOT NULL,
    "is_active" BOOLEAN NOT NULL DEFAULT true,
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."calibration_session" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "department_id" UUID,
    "status" "platform_performance"."CalibrationSessionStatus" NOT NULL DEFAULT 'SCHEDULED',
    "scheduled_at" TIMESTAMPTZ(3) NOT NULL,
    "completed_at" TIMESTAMPTZ(3),
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."calibration_participant" (
    "id" UUID NOT NULL,
    "session_id" UUID NOT NULL,
    "user_id" UUID NOT NULL,
    "role" "platform_performance"."CalibrationRole" NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "platform_performance"."grade_adjustment_log" (
    "id" UUID NOT NULL,
    "assessment_id" UUID NOT NULL,
    "session_id" UUID,
    "previous_grade_code" TEXT NOT NULL,
    "new_grade_code" TEXT NOT NULL,
    "reason" TEXT NOT NULL,
    "adjusted_by" UUID NOT NULL,
    "adjusted_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateTable
CREATE TABLE "platform_performance"."interview" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "employee_id" UUID NOT NULL,
    "manager_id" UUID NOT NULL,
    "type" "platform_performance"."InterviewType" NOT NULL,
    "status" "platform_performance"."InterviewStatus" NOT NULL DEFAULT 'SCHEDULED',
    "scheduled_at" TIMESTAMPTZ(3) NOT NULL,
    "actual_at" TIMESTAMPTZ(3),
    "duration" INTEGER,
    "topics" JSONB,
    "summary" TEXT,
    "agreements" JSONB,
    "next_steps" TEXT,
    "employee_acknowledged" BOOLEAN NOT NULL DEFAULT false,
    "employee_feedback" TEXT,
    "acknowledged_at" TIMESTAMPTZ(3),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "platform_performance"."continuous_feedback" (
    "id" UUID NOT NULL,
    "from_user_id" UUID NOT NULL,
    "to_user_id" UUID NOT NULL,
    "type" "platform_performance"."PerformanceFeedbackType" NOT NULL,
    "content" TEXT NOT NULL,
    "is_anonymous" BOOLEAN NOT NULL DEFAULT false,
    "is_read" BOOLEAN NOT NULL DEFAULT false,
    "read_at" TIMESTAMPTZ(3),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "grade_config_is_default_is_active_idx" ON "platform_performance"."grade_config"("is_default", "is_active");

-- CreateIndex
CREATE INDEX "performance_cycle_status_idx" ON "platform_performance"."performance_cycle"("status");

-- CreateIndex
CREATE INDEX "performance_cycle_start_date_end_date_idx" ON "platform_performance"."performance_cycle"("start_date", "end_date");

-- CreateIndex
CREATE INDEX "performance_cycle_type_status_idx" ON "platform_performance"."performance_cycle"("type", "status");

-- CreateIndex
CREATE INDEX "performance_result_employee_id_is_published_idx" ON "platform_performance"."performance_result"("employee_id", "is_published");

-- CreateIndex
CREATE UNIQUE INDEX "performance_result_cycle_id_employee_id_key" ON "platform_performance"."performance_result"("cycle_id", "employee_id");

-- CreateIndex
CREATE INDEX "objective_cycle_id_owner_id_idx" ON "platform_performance"."objective"("cycle_id", "owner_id");

-- CreateIndex
CREATE INDEX "objective_cycle_id_status_idx" ON "platform_performance"."objective"("cycle_id", "status");

-- CreateIndex
CREATE INDEX "objective_parent_id_idx" ON "platform_performance"."objective"("parent_id");

-- CreateIndex
CREATE INDEX "key_result_objective_id_idx" ON "platform_performance"."key_result"("objective_id");

-- CreateIndex
CREATE INDEX "kr_progress_history_key_result_id_recorded_at_idx" ON "platform_performance"."kr_progress_history"("key_result_id", "recorded_at");

-- CreateIndex
CREATE INDEX "kpi_indicator_category_is_active_idx" ON "platform_performance"."kpi_indicator"("category", "is_active");

-- CreateIndex
CREATE INDEX "kpi_assignment_cycle_id_employee_id_idx" ON "platform_performance"."kpi_assignment"("cycle_id", "employee_id");

-- CreateIndex
CREATE UNIQUE INDEX "kpi_assignment_cycle_id_employee_id_indicator_id_key" ON "platform_performance"."kpi_assignment"("cycle_id", "employee_id", "indicator_id");

-- CreateIndex
CREATE UNIQUE INDEX "kpi_assessment_assignment_id_key" ON "platform_performance"."kpi_assessment"("assignment_id");

-- CreateIndex
CREATE INDEX "kpi_assessment_status_idx" ON "platform_performance"."kpi_assessment"("status");

-- CreateIndex
CREATE INDEX "evaluation_360_cycle_id_target_id_idx" ON "platform_performance"."evaluation_360"("cycle_id", "target_id");

-- CreateIndex
CREATE INDEX "evaluation_360_status_idx" ON "platform_performance"."evaluation_360"("status");

-- CreateIndex
CREATE INDEX "evaluation_task_evaluator_id_status_idx" ON "platform_performance"."evaluation_task"("evaluator_id", "status");

-- CreateIndex
CREATE UNIQUE INDEX "evaluation_task_evaluation_id_evaluator_id_key" ON "platform_performance"."evaluation_task"("evaluation_id", "evaluator_id");

-- CreateIndex
CREATE INDEX "evaluation_response_task_id_idx" ON "platform_performance"."evaluation_response"("task_id");

-- CreateIndex
CREATE INDEX "calibration_session_cycle_id_status_idx" ON "platform_performance"."calibration_session"("cycle_id", "status");

-- CreateIndex
CREATE UNIQUE INDEX "calibration_participant_session_id_user_id_key" ON "platform_performance"."calibration_participant"("session_id", "user_id");

-- CreateIndex
CREATE INDEX "grade_adjustment_log_assessment_id_idx" ON "platform_performance"."grade_adjustment_log"("assessment_id");

-- CreateIndex
CREATE INDEX "grade_adjustment_log_session_id_idx" ON "platform_performance"."grade_adjustment_log"("session_id");

-- CreateIndex
CREATE INDEX "interview_cycle_id_employee_id_idx" ON "platform_performance"."interview"("cycle_id", "employee_id");

-- CreateIndex
CREATE INDEX "interview_manager_id_status_idx" ON "platform_performance"."interview"("manager_id", "status");

-- CreateIndex
CREATE UNIQUE INDEX "interview_cycle_id_employee_id_type_key" ON "platform_performance"."interview"("cycle_id", "employee_id", "type");

-- CreateIndex
CREATE INDEX "continuous_feedback_to_user_id_created_at_idx" ON "platform_performance"."continuous_feedback"("to_user_id", "created_at" DESC);

-- CreateIndex
CREATE INDEX "continuous_feedback_from_user_id_created_at_idx" ON "platform_performance"."continuous_feedback"("from_user_id", "created_at" DESC);

-- AddForeignKey
ALTER TABLE "platform_performance"."performance_cycle" ADD CONSTRAINT "performance_cycle_grade_config_id_fkey" FOREIGN KEY ("grade_config_id") REFERENCES "platform_performance"."grade_config"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."performance_cycle" ADD CONSTRAINT "performance_cycle_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "platform_performance"."cycle_template"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."performance_result" ADD CONSTRAINT "performance_result_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."objective" ADD CONSTRAINT "objective_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."objective" ADD CONSTRAINT "objective_parent_id_fkey" FOREIGN KEY ("parent_id") REFERENCES "platform_performance"."objective"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."key_result" ADD CONSTRAINT "key_result_objective_id_fkey" FOREIGN KEY ("objective_id") REFERENCES "platform_performance"."objective"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."kr_progress_history" ADD CONSTRAINT "kr_progress_history_key_result_id_fkey" FOREIGN KEY ("key_result_id") REFERENCES "platform_performance"."key_result"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."kpi_assignment" ADD CONSTRAINT "kpi_assignment_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."kpi_assignment" ADD CONSTRAINT "kpi_assignment_indicator_id_fkey" FOREIGN KEY ("indicator_id") REFERENCES "platform_performance"."kpi_indicator"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."kpi_assessment" ADD CONSTRAINT "kpi_assessment_assignment_id_fkey" FOREIGN KEY ("assignment_id") REFERENCES "platform_performance"."kpi_assignment"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."evaluation_360" ADD CONSTRAINT "evaluation_360_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."evaluation_360" ADD CONSTRAINT "evaluation_360_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "platform_performance"."assessment_template"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."evaluation_task" ADD CONSTRAINT "evaluation_task_evaluation_id_fkey" FOREIGN KEY ("evaluation_id") REFERENCES "platform_performance"."evaluation_360"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."evaluation_response" ADD CONSTRAINT "evaluation_response_task_id_fkey" FOREIGN KEY ("task_id") REFERENCES "platform_performance"."evaluation_task"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."calibration_session" ADD CONSTRAINT "calibration_session_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."calibration_participant" ADD CONSTRAINT "calibration_participant_session_id_fkey" FOREIGN KEY ("session_id") REFERENCES "platform_performance"."calibration_session"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."grade_adjustment_log" ADD CONSTRAINT "grade_adjustment_log_assessment_id_fkey" FOREIGN KEY ("assessment_id") REFERENCES "platform_performance"."kpi_assessment"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."grade_adjustment_log" ADD CONSTRAINT "grade_adjustment_log_session_id_fkey" FOREIGN KEY ("session_id") REFERENCES "platform_performance"."calibration_session"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."interview" ADD CONSTRAINT "interview_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
