import { boolean, jsonb, pgTable, text, timestamp } from 'drizzle-orm/pg-core';

export const pushSubscriptions = pgTable('push_subscriptions', {
  id: text('id').primaryKey(),
  userId: text('user_id').notNull(),
  endpoint: text('endpoint').notNull(),
  p256dh: text('p256dh').notNull(),
  auth: text('auth').notNull(),
  createdAt: timestamp('created_at').defaultNow().notNull(),
});

export const notificationPreferences = pgTable('notification_preferences', {
  userId: text('user_id').primaryKey(),
  pushOnAnswer: boolean('push_on_answer').default(true),
  emailOnDeepResearch: boolean('email_on_deep_research').default(false),
  reminders: jsonb('reminders').$type<unknown[]>().default([]),
  updatedAt: timestamp('updated_at').defaultNow().notNull(),
});

export const reminders = pgTable('reminders', {
  id: text('id').primaryKey(),
  userId: text('user_id').notNull(),
  threadId: text('thread_id'),
  query: text('query'),
  remindAt: timestamp('remind_at').notNull(),
  createdAt: timestamp('created_at').defaultNow().notNull(),
  sentAt: timestamp('sent_at'),
});
