-- CreateTable
CREATE TABLE "benefit_assessment_query_view" (
    "id" TEXT NOT NULL,
    "authorization_id" TEXT NOT NULL,
    "user_id" TEXT NOT NULL,
    "account_sequence" TEXT NOT NULL,
    "role_type" VARCHAR(30) 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" VARCHAR(20) NOT NULL,
    "previous_benefit_status" BOOLEAN NOT NULL,
    "new_benefit_status" BOOLEAN NOT NULL,
    "new_valid_until" TIMESTAMP(3),
    "result" VARCHAR(20) NOT NULL DEFAULT 'NOT_ASSESSED',
    "remarks" VARCHAR(500),
    "assessed_at" TIMESTAMP(3) NOT NULL,
    "created_at" TIMESTAMP(3) NOT NULL,
    "synced_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

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

-- CreateIndex
CREATE INDEX "benefit_assessment_query_view_account_sequence_assessment_m_idx" ON "benefit_assessment_query_view"("account_sequence", "assessment_month");

-- CreateIndex
CREATE INDEX "benefit_assessment_query_view_user_id_assessment_month_idx" ON "benefit_assessment_query_view"("user_id", "assessment_month");

-- CreateIndex
CREATE INDEX "benefit_assessment_query_view_role_type_region_code_assessm_idx" ON "benefit_assessment_query_view"("role_type", "region_code", "assessment_month");

-- CreateIndex
CREATE INDEX "benefit_assessment_query_view_assessment_month_result_idx" ON "benefit_assessment_query_view"("assessment_month", "result");

-- CreateIndex
CREATE UNIQUE INDEX "benefit_assessment_query_view_authorization_id_assessment_m_key" ON "benefit_assessment_query_view"("authorization_id", "assessment_month");
