/**
 * Optional saved clinical assistant chats. These are user-triggered saves,
 * encrypted at rest like personal_notes because answers may contain PHI.
 */

exports.up = (pgm) => {
  pgm.createTable('clinical_assistant_chats', {
    id:         { type: 'serial', primaryKey: true },
    user_id:    { type: 'integer', notNull: true, references: 'users(id)', onDelete: 'CASCADE' },
    title:      { type: 'text', notNull: true },
    payload:    { type: 'text', notNull: true, default: '{}' },
    created_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
    updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
  });
  pgm.createIndex('clinical_assistant_chats', 'user_id');
  pgm.createIndex('clinical_assistant_chats', ['user_id', 'updated_at']);
};

exports.down = (pgm) => {
  pgm.dropTable('clinical_assistant_chats');
};
