import { describe, expect, it } from 'vitest'
import { notificationsSchema, notificationsTableSql } from './inbox-schema.js'

describe('inbox-schema', () => {
  it('exposes a notifications table in the schema map', () => {
    expect(notificationsSchema.notifications).toBeDefined()
  })
  it('DDL has user-scoped keyset index + partial unread index, matching column names', () => {
    const sql = notificationsTableSql()
    expect(sql).toContain('CREATE TABLE IF NOT EXISTS notifications')
    expect(sql).toContain('seq        bigserial NOT NULL')
    expect(sql).toContain('id         text PRIMARY KEY')
    expect(sql).toContain('user_id    text NOT NULL')
    expect(sql).toContain('created_at_ms bigint NOT NULL')
    expect(sql).toContain('read_at    text NULL')
    expect(sql).toContain('notifications_user_keyset_idx ON notifications (user_id, created_at_ms, seq)')
    expect(sql).toContain('notifications_user_unread_idx ON notifications (user_id) WHERE read_at IS NULL')
  })
  it('honors a custom table name', () => {
    expect(notificationsTableSql('inbox_items')).toContain('CREATE TABLE IF NOT EXISTS inbox_items')
  })
})
