-- CreateEnum
CREATE TYPE "TreatmentType" AS ENUM ('EMERGENCY', 'INPATIENT', 'OUTPATIENT', 'SURGERY', 'PHYSIOTHERAPY', 'DIAGNOSTIC', 'MEDICAL_EXAMINATION', 'FOLLOW_UP', 'OTHER');

-- CreateEnum
CREATE TYPE "TreatmentStatus" AS ENUM ('REPORTED', 'RECORDS_REQUESTED', 'RECORDS_RECEIVED', 'VERIFIED');

-- CreateEnum
CREATE TYPE "EvidenceRequestType" AS ENUM ('MEDICAL_RECORDS', 'MEDICAL_REPORT', 'MEDICAL_BILLS', 'P3_FORM', 'POLICE_ABSTRACT', 'OCCURRENCE_BOOK', 'EMPLOYMENT_RECORDS', 'WITNESS_STATEMENT', 'EXPERT_REPORT', 'OTHER');

-- CreateEnum
CREATE TYPE "EvidenceRequestStatus" AS ENUM ('IDENTIFIED', 'REQUESTED', 'FOLLOW_UP_DUE', 'PARTIALLY_RECEIVED', 'RECEIVED', 'VERIFIED', 'UNAVAILABLE');

-- CreateEnum
CREATE TYPE "InsuranceClaimStatus" AS ENUM ('NOTIFIED', 'ACKNOWLEDGED', 'INVESTIGATING', 'LIABILITY_ADMITTED', 'LIABILITY_DISPUTED', 'REPUDIATED', 'NEGOTIATING', 'SETTLED', 'CLOSED');

-- CreateEnum
CREATE TYPE "DamageCategory" AS ENUM ('MEDICAL_EXPENSE', 'TRANSPORT', 'LOSS_OF_INCOME', 'LOSS_OF_EARNING_CAPACITY', 'FUTURE_CARE', 'DEPENDENCY', 'FUNERAL_EXPENSE', 'PROPERTY_DAMAGE', 'GENERAL_DAMAGES', 'OTHER_SPECIAL_DAMAGE');

-- CreateEnum
CREATE TYPE "DamageStatus" AS ENUM ('CLAIMED', 'SUPPORTED', 'DISPUTED', 'AGREED', 'AWARDED', 'PAID', 'REJECTED');

-- CreateTable
CREATE TABLE "treatment_records" (
    "id" TEXT NOT NULL,
    "caseId" TEXT NOT NULL,
    "providerName" TEXT NOT NULL,
    "treatmentDate" TIMESTAMP(3) NOT NULL,
    "type" "TreatmentType" NOT NULL,
    "diagnosis" TEXT,
    "procedure" TEXT,
    "restrictions" TEXT,
    "prognosis" TEXT,
    "amount" DECIMAL(14,2),
    "currency" TEXT NOT NULL DEFAULT 'KES',
    "status" "TreatmentStatus" NOT NULL DEFAULT 'REPORTED',
    "notes" TEXT,
    "createdBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "evidence_requests" (
    "id" TEXT NOT NULL,
    "caseId" TEXT NOT NULL,
    "type" "EvidenceRequestType" NOT NULL,
    "custodianName" TEXT NOT NULL,
    "reference" TEXT,
    "requestedAt" TIMESTAMP(3),
    "dueAt" TIMESTAMP(3),
    "receivedAt" TIMESTAMP(3),
    "status" "EvidenceRequestStatus" NOT NULL DEFAULT 'IDENTIFIED',
    "requestedRange" TEXT,
    "missingItems" TEXT,
    "feeAmount" DECIMAL(14,2),
    "notes" TEXT,
    "createdBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "insurance_claims" (
    "id" TEXT NOT NULL,
    "caseId" TEXT NOT NULL,
    "insurerName" TEXT NOT NULL,
    "insuredName" TEXT,
    "policyNumber" TEXT,
    "claimNumber" TEXT,
    "adjusterName" TEXT,
    "adjusterEmail" TEXT,
    "adjusterPhone" TEXT,
    "coverageType" TEXT,
    "limitAmount" DECIMAL(14,2),
    "status" "InsuranceClaimStatus" NOT NULL DEFAULT 'NOTIFIED',
    "admissionNotes" TEXT,
    "repudiationNotes" TEXT,
    "createdBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateTable
CREATE TABLE "damage_items" (
    "id" TEXT NOT NULL,
    "caseId" TEXT NOT NULL,
    "category" "DamageCategory" NOT NULL,
    "description" TEXT NOT NULL,
    "amount" DECIMAL(14,2) NOT NULL,
    "currency" TEXT NOT NULL DEFAULT 'KES',
    "status" "DamageStatus" NOT NULL DEFAULT 'CLAIMED',
    "calculation" TEXT,
    "evidenceReference" TEXT,
    "incurredAt" TIMESTAMP(3),
    "createdBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

-- CreateIndex
CREATE INDEX "treatment_records_caseId_treatmentDate_idx" ON "treatment_records"("caseId", "treatmentDate");

-- CreateIndex
CREATE INDEX "evidence_requests_caseId_status_idx" ON "evidence_requests"("caseId", "status");

-- CreateIndex
CREATE INDEX "evidence_requests_dueAt_idx" ON "evidence_requests"("dueAt");

-- CreateIndex
CREATE INDEX "insurance_claims_caseId_status_idx" ON "insurance_claims"("caseId", "status");

-- CreateIndex
CREATE INDEX "insurance_claims_claimNumber_idx" ON "insurance_claims"("claimNumber");

-- CreateIndex
CREATE INDEX "damage_items_caseId_category_idx" ON "damage_items"("caseId", "category");

-- CreateIndex
CREATE INDEX "damage_items_status_idx" ON "damage_items"("status");

-- AddForeignKey
ALTER TABLE "treatment_records" ADD CONSTRAINT "treatment_records_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "cases"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "evidence_requests" ADD CONSTRAINT "evidence_requests_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "cases"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "insurance_claims" ADD CONSTRAINT "insurance_claims_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "cases"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "damage_items" ADD CONSTRAINT "damage_items_caseId_fkey" FOREIGN KEY ("caseId") REFERENCES "cases"("id") ON DELETE CASCADE ON UPDATE CASCADE;
