-- CreateEnum
CREATE TYPE "BenefitActionType" AS ENUM ('ACTIVATED', 'RENEWED', 'DEACTIVATED', 'NO_CHANGE');

-- CreateTable
CREATE TABLE "benefit_assessment_records" (
    "id" TEXT NOT NULL,
    "authorization_id" TEXT NOT NULL,
    "user_id" TEXT NOT NULL,
    "account_sequence" TEXT NOT NULL,
    "role_type" "RoleType" NOT NULL,
    "region_code" TEXT NOT NULL,
    "region_name" TEXT NOT NULL,
    "assessment_month" TEXT NOT NULL,
    "month_index" INTEGER NOT NULL,
    "monthly_target" INTEGER NOT NULL,
    "cumulative_target" INTEGER NOT NULL,
    "trees_completed" INTEGER NOT NULL,
    "trees_required" INTEGER NOT NULL,
    "benefit_action_taken" "BenefitActionType" NOT NULL,
    "previous_benefit_status" BOOLEAN NOT NULL,
    "new_benefit_status" BOOLEAN NOT NULL,
    "new_valid_until" TIMESTAMP(3),
    "result" "AssessmentResult" NOT NULL DEFAULT 'NOT_ASSESSED',
    "remarks" VARCHAR(500),
    "assessed_at" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "benefit_assessment_records_account_sequence_assessment_mont_idx" ON "benefit_assessment_records"("account_sequence", "assessment_month");

-- CreateIndex
CREATE INDEX "benefit_assessment_records_user_id_assessment_month_idx" ON "benefit_assessment_records"("user_id", "assessment_month");

-- CreateIndex
CREATE INDEX "benefit_assessment_records_role_type_region_code_assessment_idx" ON "benefit_assessment_records"("role_type", "region_code", "assessment_month");

-- CreateIndex
CREATE INDEX "benefit_assessment_records_assessment_month_result_idx" ON "benefit_assessment_records"("assessment_month", "result");

-- CreateIndex
CREATE UNIQUE INDEX "benefit_assessment_records_authorization_id_assessment_mont_key" ON "benefit_assessment_records"("authorization_id", "assessment_month");
