// Two additions:
//
// 1. asset_id — direct FK to shared_assets, preferred over minio_object_key
//    for segments created through the editor UI. Gnommo-ingested segments
//    continue to use minio_object_key; asset_id is NULL for those.
//
// 2. segment_type — 'raw' for original recordings, 'final' for the
//    processed/transcoded versions that the player actually consumes.
//    The GnommoPlayer export uses the 'final' list; 'raw' is for reference
//    and source-of-truth tracking.

exports.up = (pgm) => {
  pgm.addColumns('narration_segments', {
    asset_id: {
      type: 'integer',
      references: 'shared_assets',
      onDelete: 'SET NULL',
    },
    segment_type: {
      type: 'varchar(10)',
      notNull: true,
      default: "'raw'",
    },
  });

  pgm.createIndex('narration_segments', ['project_id', 'segment_type', 'sort_order'], {
    name: 'idx_narration_segments_type_order',
  });
};

exports.down = (pgm) => {
  pgm.dropIndex('narration_segments', null, { name: 'idx_narration_segments_type_order' });
  pgm.dropColumns('narration_segments', ['asset_id', 'segment_type']);
};
