-- CreateTable
CREATE TABLE "TokenConfig" (
    "id" TEXT NOT NULL PRIMARY KEY DEFAULT 'singleton',
    "enabled" BOOLEAN NOT NULL DEFAULT true,
    "chatModel" TEXT NOT NULL DEFAULT 'google/gemini-2.5-flash',
    "researchModel" TEXT NOT NULL DEFAULT 'anthropic/claude-sonnet-4.6',
    "reasoningModel" TEXT NOT NULL DEFAULT 'deepseek/deepseek-r1',
    "classificationModel" TEXT NOT NULL DEFAULT 'google/gemini-2.5-flash-lite',
    "systemPrompt" TEXT NOT NULL DEFAULT '',
    "maxTokensPerReply" INTEGER NOT NULL DEFAULT 4096,
    "temperature" REAL NOT NULL DEFAULT 0.4,
    "monthlyBudgetUsd" REAL NOT NULL DEFAULT 50.0,
    "totalSpentUsd" REAL NOT NULL DEFAULT 0.0,
    "updatedAt" DATETIME NOT NULL
);

-- CreateTable
CREATE TABLE "TokenConversation" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "userId" TEXT NOT NULL,
    "title" TEXT NOT NULL DEFAULT 'New conversation',
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" DATETIME NOT NULL,
    CONSTRAINT "TokenConversation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "TokenMessage" (
    "id" TEXT NOT NULL PRIMARY KEY,
    "conversationId" TEXT NOT NULL,
    "role" TEXT NOT NULL,
    "content" TEXT NOT NULL,
    "model" TEXT,
    "inputTokens" INTEGER NOT NULL DEFAULT 0,
    "outputTokens" INTEGER NOT NULL DEFAULT 0,
    "costUsd" REAL NOT NULL DEFAULT 0.0,
    "latencyMs" INTEGER NOT NULL DEFAULT 0,
    "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT "TokenMessage_conversationId_fkey" FOREIGN KEY ("conversationId") REFERENCES "TokenConversation" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);

-- CreateIndex
CREATE INDEX "TokenConversation_userId_idx" ON "TokenConversation"("userId");

-- CreateIndex
CREATE INDEX "TokenMessage_conversationId_idx" ON "TokenMessage"("conversationId");
