exports.up = (pgm) => {
  pgm.createTable('slides', {
    id: 'id',
    video_id: {
      type: 'integer',
      notNull: true,
      references: 'videos',
      onDelete: 'CASCADE',
    },
    gnommo_slide_id: { type: 'varchar(20)', notNull: true },
    slide_order: { type: 'integer', notNull: true },
    image_filename: { type: 'varchar(500)' },
    display_mode: { type: 'varchar(50)' },
    component_key: { type: 'varchar(100)' },
    props: { type: 'jsonb' },
    presenter_notes: { type: 'text' },
    start_time_sec: { type: 'numeric' },
    end_time_sec: { type: 'numeric' },
    created_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
    updated_at: { type: 'timestamptz', notNull: true, default: pgm.func('NOW()') },
  });

  pgm.addConstraint('slides', 'slides_video_id_gnommo_slide_id_unique', 'UNIQUE (video_id, gnommo_slide_id)');
  pgm.createIndex('slides', 'video_id', { name: 'idx_slides_video_id' });
  pgm.createIndex('slides', ['video_id', 'slide_order'], { name: 'idx_slides_video_order' });
};

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