import { pgTable, text, timestamp, integer, serial } from "drizzle-orm/pg-core";
import { sessions } from "./sessions";

// ── session_messages ────────────────────────────────────────────────────────
// Stores conversation history for context injection into the work model.

export const sessionMessages = pgTable("session_messages", {
  id: serial("id").primaryKey(),
  sessionId: text("session_id")
    .notNull()
    .references(() => sessions.id),
  role: text("role").$type<"user" | "assistant">().notNull(),
  content: text("content").notNull(),
  tokenCount: integer("token_count"),
  createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
});

export type SessionMessage = typeof sessionMessages.$inferSelect;
