import { sql } from "drizzle-orm"; import { pgTable, text, varchar, integer, boolean, timestamp } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { z } from "zod"; export const sessions = pgTable("sessions", { id: varchar("id").primaryKey().default(sql`gen_random_uuid()`), deviceId: text("device_id").notNull(), type: text("type").notNull(), // 'focus' | 'break' intendedMinutes: integer("intended_minutes").notNull(), actualSeconds: integer("actual_seconds").notNull(), startedAt: timestamp("started_at").notNull(), endedAt: timestamp("ended_at").notNull(), completed: boolean("completed").notNull(), interruptions: integer("interruptions").notNull().default(0), }); export const deviceProfiles = pgTable("device_profiles", { id: varchar("id").primaryKey().default(sql`gen_random_uuid()`), deviceId: text("device_id").notNull().unique(), createdAt: timestamp("created_at").notNull().default(sql`now()`), lastActiveAt: timestamp("last_active_at").notNull().default(sql`now()`), }); export const insertSessionSchema = createInsertSchema(sessions).omit({ id: true, }); export const insertDeviceProfileSchema = createInsertSchema(deviceProfiles).omit({ id: true, createdAt: true, lastActiveAt: true, }); export type InsertSession = z.infer; export type Session = typeof sessions.$inferSelect; export type InsertDeviceProfile = z.infer; export type DeviceProfile = typeof deviceProfiles.$inferSelect;