-- P2-15: 人工咨询服务 Consultation 表
CREATE TABLE "Consultation" (
    "id" TEXT NOT NULL,
    "orgId" TEXT NOT NULL,
    "type" TEXT NOT NULL,
    "title" TEXT NOT NULL,
    "description" TEXT NOT NULL,
    "contactName" TEXT NOT NULL,
    "contactPhone" TEXT NOT NULL,
    "status" TEXT NOT NULL DEFAULT 'PENDING',
    "aiConversationId" TEXT,
    "remark" TEXT,
    "createdBy" TEXT NOT NULL,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

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

CREATE INDEX "Consultation_orgId_status_idx" ON "Consultation"("orgId", "status");
CREATE INDEX "Consultation_orgId_type_idx" ON "Consultation"("orgId", "type");

-- 外键
ALTER TABLE "Consultation" ADD CONSTRAINT "Consultation_orgId_fkey"
    FOREIGN KEY ("orgId") REFERENCES "Organization"("id") ON DELETE CASCADE;
