-- Add Llm.kind/status discriminators and virtual-provider lifecycle fields.
-- Existing rows backfill with kind='public' / status='active' so v1 is purely
-- additive — public LLMs ignore the lifecycle columns entirely.

CREATE TYPE "LlmKind" AS ENUM ('public', 'virtual');
CREATE TYPE "LlmStatus" AS ENUM ('active', 'inactive', 'hibernating');

ALTER TABLE "Llm"
  ADD COLUMN "kind"               "LlmKind"   NOT NULL DEFAULT 'public',
  ADD COLUMN "providerSessionId"  TEXT,
  ADD COLUMN "lastHeartbeatAt"    TIMESTAMP(3),
  ADD COLUMN "status"             "LlmStatus" NOT NULL DEFAULT 'active',
  ADD COLUMN "inactiveSince"      TIMESTAMP(3);

CREATE INDEX "Llm_kind_status_idx"          ON "Llm"("kind", "status");
CREATE INDEX "Llm_providerSessionId_idx"    ON "Llm"("providerSessionId");
