/*
  Warnings:

  - The values [RELEASED] on the enum `Evaluation360Status` will be removed. If these variants are still used in the database, this will fail.
  - You are about to drop the column `released_at` on the `evaluation_360` table. All the data in the column will be lost.
  - You are about to drop the column `assessment_id` on the `grade_adjustment_log` table. All the data in the column will be lost.
  - You are about to drop the column `session_id` on the `grade_adjustment_log` table. All the data in the column will be lost.
  - You are about to drop the column `confirmed_at` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `final_grade_code` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `grade_adjust_reason` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `grade_adjusted_at` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `grade_adjusted_by` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `proposed_grade_code` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `quarter_scores` on the `kpi_assessment` table. All the data in the column will be lost.
  - You are about to drop the column `annual_target_value` on the `kpi_assignment` table. All the data in the column will be lost.
  - You are about to drop the column `indicator_id` on the `kpi_assignment` table. All the data in the column will be lost.
  - You are about to drop the column `quarter_targets` on the `kpi_assignment` table. All the data in the column will be lost.
  - You are about to drop the column `evaluation_start_date` on the `performance_cycle` table. All the data in the column will be lost.
  - You are about to drop the column `execution_start_date` on the `performance_cycle` table. All the data in the column will be lost.
  - You are about to drop the column `goal_deadline` on the `performance_cycle` table. All the data in the column will be lost.
  - You are about to drop the column `template_id` on the `performance_cycle` table. All the data in the column will be lost.
  - You are about to drop the `assessment_template` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `calibration_participant` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `calibration_session` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `continuous_feedback` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `cycle_template` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `interview` table. If the table is not empty, all the data it contains will be lost.
  - You are about to drop the `kpi_indicator` table. If the table is not empty, all the data it contains will be lost.
  - A unique constraint covering the columns `[cycle_id,employee_id,name]` on the table `kpi_assignment` will be added. If there are existing duplicate values, this will fail.
  - Added the required column `result_id` to the `grade_adjustment_log` table without a default value. This is not possible if the table is not empty.
  - Added the required column `name` to the `kpi_assignment` table without a default value. This is not possible if the table is not empty.
  - Added the required column `organization_id` to the `performance_cycle` table without a default value. This is not possible if the table is not empty.
  - Added the required column `organization_id` to the `performance_result` table without a default value. This is not possible if the table is not empty.

*/
-- CreateEnum
CREATE TYPE "platform_performance"."KpiAssignmentStatus" AS ENUM ('DRAFT', 'SUBMITTED', 'APPROVED', 'REJECTED');

-- CreateEnum
CREATE TYPE "platform_performance"."KpiDependencyStatus" AS ENUM ('PENDING', 'CONFIRMED', 'REJECTED');

-- CreateEnum
CREATE TYPE "platform_performance"."ResultConfirmStatus" AS ENUM ('PENDING', 'CONFIRMED', 'APPEALED', 'APPEAL_RESOLVED');

-- AlterEnum
ALTER TYPE "platform_performance"."CycleStatus" ADD VALUE 'CONFIRMING';

-- AlterEnum
BEGIN;
CREATE TYPE "platform_performance"."Evaluation360Status_new" AS ENUM ('DRAFT', 'IN_PROGRESS', 'COLLECTING', 'COMPLETED', 'CANCELLED');
ALTER TABLE "platform_performance"."evaluation_360" ALTER COLUMN "status" DROP DEFAULT;
ALTER TABLE "platform_performance"."evaluation_360" ALTER COLUMN "status" TYPE "platform_performance"."Evaluation360Status_new" USING ("status"::text::"platform_performance"."Evaluation360Status_new");
ALTER TYPE "platform_performance"."Evaluation360Status" RENAME TO "Evaluation360Status_old";
ALTER TYPE "platform_performance"."Evaluation360Status_new" RENAME TO "Evaluation360Status";
DROP TYPE "platform_performance"."Evaluation360Status_old";
ALTER TABLE "platform_performance"."evaluation_360" ALTER COLUMN "status" SET DEFAULT 'DRAFT';
COMMIT;

-- AlterEnum
ALTER TYPE "platform_performance"."RelationType" ADD VALUE 'CROSS_FUNCTIONAL';

-- DropForeignKey
ALTER TABLE "platform_performance"."calibration_participant" DROP CONSTRAINT "calibration_participant_session_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."calibration_session" DROP CONSTRAINT "calibration_session_cycle_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."evaluation_360" DROP CONSTRAINT "evaluation_360_template_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."grade_adjustment_log" DROP CONSTRAINT "grade_adjustment_log_assessment_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."grade_adjustment_log" DROP CONSTRAINT "grade_adjustment_log_session_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."interview" DROP CONSTRAINT "interview_cycle_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."kpi_assignment" DROP CONSTRAINT "kpi_assignment_indicator_id_fkey";

-- DropForeignKey
ALTER TABLE "platform_performance"."performance_cycle" DROP CONSTRAINT "performance_cycle_template_id_fkey";

-- DropIndex
DROP INDEX "platform_meeting_attendance"."outlook_sync_bindings_primary_mailbox_id_graph_event_id_key";

-- DropIndex
DROP INDEX "platform_performance"."grade_adjustment_log_assessment_id_idx";

-- DropIndex
DROP INDEX "platform_performance"."grade_adjustment_log_session_id_idx";

-- DropIndex
DROP INDEX "platform_performance"."kpi_assignment_cycle_id_employee_id_indicator_id_key";

-- AlterTable
ALTER TABLE "platform_performance"."evaluation_360" DROP COLUMN "released_at";

-- AlterTable
ALTER TABLE "platform_performance"."grade_adjustment_log" DROP COLUMN "assessment_id",
DROP COLUMN "session_id",
ADD COLUMN     "result_id" UUID NOT NULL;

-- AlterTable
ALTER TABLE "platform_performance"."grade_config" ADD COLUMN     "organization_id" UUID;

-- AlterTable
ALTER TABLE "platform_performance"."kpi_assessment" DROP COLUMN "confirmed_at",
DROP COLUMN "final_grade_code",
DROP COLUMN "grade_adjust_reason",
DROP COLUMN "grade_adjusted_at",
DROP COLUMN "grade_adjusted_by",
DROP COLUMN "proposed_grade_code",
DROP COLUMN "quarter_scores",
ADD COLUMN     "completion_note" TEXT;

-- AlterTable
ALTER TABLE "platform_performance"."kpi_assignment" DROP COLUMN "annual_target_value",
DROP COLUMN "indicator_id",
DROP COLUMN "quarter_targets",
ADD COLUMN     "assignment_status" "platform_performance"."KpiAssignmentStatus" NOT NULL DEFAULT 'DRAFT',
ADD COLUMN     "base_target" TEXT,
ADD COLUMN     "description" TEXT,
ADD COLUMN     "maturity_score" DECIMAL(5,2),
ADD COLUMN     "name" TEXT NOT NULL,
ADD COLUMN     "parent_id" UUID,
ADD COLUMN     "seq" INTEGER,
ADD COLUMN     "stretch_target" TEXT,
ADD COLUMN     "unit" TEXT,
ADD COLUMN     "updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "platform_performance"."performance_cycle" DROP COLUMN "evaluation_start_date",
DROP COLUMN "execution_start_date",
DROP COLUMN "goal_deadline",
DROP COLUMN "template_id",
ADD COLUMN     "organization_id" UUID NOT NULL,
ADD COLUMN     "parent_cycle_id" UUID;

-- AlterTable
ALTER TABLE "platform_performance"."performance_result" ADD COLUMN     "appeal_reason" TEXT,
ADD COLUMN     "appeal_resolved_at" TIMESTAMPTZ(3),
ADD COLUMN     "appeal_response" TEXT,
ADD COLUMN     "confirm_status" "platform_performance"."ResultConfirmStatus" NOT NULL DEFAULT 'PENDING',
ADD COLUMN     "manager_overall_comment" TEXT,
ADD COLUMN     "organization_id" UUID NOT NULL,
ADD COLUMN     "proposed_grade_code" TEXT,
ADD COLUMN     "proposed_grade_name" TEXT,
ADD COLUMN     "self_overall_comment" TEXT,
ALTER COLUMN "total_score" DROP NOT NULL,
ALTER COLUMN "grade_code" DROP NOT NULL,
ALTER COLUMN "grade_name" DROP NOT NULL;

-- DropTable
DROP TABLE "platform_performance"."assessment_template";

-- DropTable
DROP TABLE "platform_performance"."calibration_participant";

-- DropTable
DROP TABLE "platform_performance"."calibration_session";

-- DropTable
DROP TABLE "platform_performance"."continuous_feedback";

-- DropTable
DROP TABLE "platform_performance"."cycle_template";

-- DropTable
DROP TABLE "platform_performance"."interview";

-- DropTable
DROP TABLE "platform_performance"."kpi_indicator";

-- DropEnum
DROP TYPE "platform_performance"."AssessmentTemplateType";

-- DropEnum
DROP TYPE "platform_performance"."CalibrationRole";

-- DropEnum
DROP TYPE "platform_performance"."CalibrationSessionStatus";

-- DropEnum
DROP TYPE "platform_performance"."InterviewStatus";

-- DropEnum
DROP TYPE "platform_performance"."InterviewType";

-- DropEnum
DROP TYPE "platform_performance"."PerformanceFeedbackType";

-- CreateTable
CREATE TABLE "platform_performance"."kpi_dependency" (
    "id" UUID NOT NULL,
    "source_assignment_id" UUID NOT NULL,
    "target_assignment_id" UUID,
    "target_user_id" UUID NOT NULL,
    "description" TEXT,
    "status" "platform_performance"."KpiDependencyStatus" NOT NULL DEFAULT 'PENDING',
    "rejection_reason" TEXT,
    "confirmed_at" TIMESTAMPTZ(3),
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,
    "deleted_at" TIMESTAMPTZ(3),

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

-- CreateTable
CREATE TABLE "platform_performance"."strategic_objective" (
    "id" UUID NOT NULL,
    "cycle_id" UUID NOT NULL,
    "seq" INTEGER NOT NULL DEFAULT 0,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "department_id" UUID,
    "created_by" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updated_at" TIMESTAMPTZ(3) NOT NULL,
    "deleted_at" TIMESTAMPTZ(3),

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

-- CreateTable
CREATE TABLE "platform_performance"."strategic_objective_assignment" (
    "id" UUID NOT NULL,
    "objective_id" UUID NOT NULL,
    "assignee_id" UUID NOT NULL,
    "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "deleted_at" TIMESTAMPTZ(3),

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

-- CreateTable
CREATE TABLE "platform_performance"."evaluation_360_template" (
    "id" UUID NOT NULL,
    "name" TEXT NOT NULL,
    "description" TEXT,
    "dimensions" JSONB NOT NULL,
    "relationship_types" 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,
    "deleted_at" TIMESTAMPTZ(3),
    "cycle_id" UUID,
    "scope" JSONB,
    "organization_id" UUID,

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

-- CreateIndex
CREATE INDEX "kpi_dependency_target_user_id_status_idx" ON "platform_performance"."kpi_dependency"("target_user_id", "status");

-- CreateIndex
CREATE INDEX "kpi_dependency_source_assignment_id_idx" ON "platform_performance"."kpi_dependency"("source_assignment_id");

-- CreateIndex
CREATE UNIQUE INDEX "kpi_dependency_source_assignment_id_target_user_id_key" ON "platform_performance"."kpi_dependency"("source_assignment_id", "target_user_id");

-- CreateIndex
CREATE INDEX "strategic_objective_cycle_id_idx" ON "platform_performance"."strategic_objective"("cycle_id");

-- CreateIndex
CREATE INDEX "strategic_objective_department_id_idx" ON "platform_performance"."strategic_objective"("department_id");

-- CreateIndex
CREATE INDEX "strategic_objective_assignment_assignee_id_idx" ON "platform_performance"."strategic_objective_assignment"("assignee_id");

-- CreateIndex
CREATE UNIQUE INDEX "strategic_objective_assignment_objective_id_assignee_id_key" ON "platform_performance"."strategic_objective_assignment"("objective_id", "assignee_id");

-- CreateIndex
CREATE INDEX "evaluation_360_template_is_default_is_active_idx" ON "platform_performance"."evaluation_360_template"("is_default", "is_active");

-- CreateIndex
CREATE INDEX "evaluation_360_template_organization_id_idx" ON "platform_performance"."evaluation_360_template"("organization_id");

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

-- CreateIndex
CREATE INDEX "evaluation_360_template_id_idx" ON "platform_performance"."evaluation_360"("template_id");

-- CreateIndex
CREATE INDEX "grade_adjustment_log_result_id_idx" ON "platform_performance"."grade_adjustment_log"("result_id");

-- CreateIndex
CREATE INDEX "grade_config_organization_id_idx" ON "platform_performance"."grade_config"("organization_id");

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

-- CreateIndex
CREATE INDEX "kpi_assignment_cycle_id_assignment_status_idx" ON "platform_performance"."kpi_assignment"("cycle_id", "assignment_status");

-- CreateIndex
CREATE INDEX "kpi_assignment_parent_id_idx" ON "platform_performance"."kpi_assignment"("parent_id");

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

-- CreateIndex
CREATE INDEX "performance_cycle_organization_id_idx" ON "platform_performance"."performance_cycle"("organization_id");

-- CreateIndex
CREATE INDEX "performance_cycle_parent_cycle_id_idx" ON "platform_performance"."performance_cycle"("parent_cycle_id");

-- CreateIndex
CREATE INDEX "performance_cycle_grade_config_id_idx" ON "platform_performance"."performance_cycle"("grade_config_id");

-- CreateIndex
CREATE INDEX "performance_result_cycle_id_confirm_status_idx" ON "platform_performance"."performance_result"("cycle_id", "confirm_status");

-- CreateIndex
CREATE INDEX "performance_result_cycle_id_grade_code_idx" ON "platform_performance"."performance_result"("cycle_id", "grade_code");

-- CreateIndex
CREATE INDEX "performance_result_organization_id_idx" ON "platform_performance"."performance_result"("organization_id");

-- AddForeignKey
ALTER TABLE "platform_performance"."grade_config" ADD CONSTRAINT "grade_config_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "corp_hr"."organizations"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."performance_cycle" ADD CONSTRAINT "performance_cycle_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "corp_hr"."organizations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "platform_performance"."performance_result" ADD CONSTRAINT "performance_result_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "corp_hr"."organizations"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "platform_performance"."kpi_dependency" ADD CONSTRAINT "kpi_dependency_source_assignment_id_fkey" FOREIGN KEY ("source_assignment_id") REFERENCES "platform_performance"."kpi_assignment"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."kpi_dependency" ADD CONSTRAINT "kpi_dependency_target_assignment_id_fkey" FOREIGN KEY ("target_assignment_id") REFERENCES "platform_performance"."kpi_assignment"("id") ON DELETE SET NULL ON UPDATE CASCADE;

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

-- AddForeignKey
ALTER TABLE "platform_performance"."grade_adjustment_log" ADD CONSTRAINT "grade_adjustment_log_result_id_fkey" FOREIGN KEY ("result_id") REFERENCES "platform_performance"."performance_result"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."strategic_objective" ADD CONSTRAINT "strategic_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"."strategic_objective_assignment" ADD CONSTRAINT "strategic_objective_assignment_objective_id_fkey" FOREIGN KEY ("objective_id") REFERENCES "platform_performance"."strategic_objective"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."strategic_objective_assignment" ADD CONSTRAINT "strategic_objective_assignment_assignee_id_fkey" FOREIGN KEY ("assignee_id") REFERENCES "platform_iam"."users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."evaluation_360_template" ADD CONSTRAINT "evaluation_360_template_cycle_id_fkey" FOREIGN KEY ("cycle_id") REFERENCES "platform_performance"."performance_cycle"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "platform_performance"."evaluation_360_template" ADD CONSTRAINT "evaluation_360_template_organization_id_fkey" FOREIGN KEY ("organization_id") REFERENCES "corp_hr"."organizations"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- RenameIndex
ALTER INDEX "platform_meeting_attendance"."outlook_series_occurrence_exclusions_binding_id_occurrence_grap" RENAME TO "outlook_series_occurrence_exclusions_binding_id_occurrence__key";

-- RenameIndex
ALTER INDEX "platform_meeting_attendance"."outlook_series_occurrence_exclusions_occurrence_graph_event_id_" RENAME TO "outlook_series_occurrence_exclusions_occurrence_graph_event_idx";
