import 'dart:typed_data';

import 'package:dio/dio.dart';

import '../../marianumconnect_query.dart';

/// Downloads the raw bytes of a PROXIED_FILE ticker page from
/// `GET /api/mobile/v1/ticker/pages/{slug}/file`.
///
/// Goes through the shared MC dio so the bearer token is attached automatically
/// (server enforces page visibility); the bytes are handed to `SfPdfViewer.memory`
/// so no auth header has to be plumbed into the viewer itself.
class GetTickerPageFile extends MarianumConnectQuery {
  final String slug;

  GetTickerPageFile(this.slug, {super.dio});

  Future<Uint8List> run() => guard(() async {
    final response = await dio.get<List<int>>(
      endpoint('ticker/pages/${Uri.encodeComponent(slug)}/file'),
      options: Options(responseType: ResponseType.bytes),
    );
    return Uint8List.fromList(response.data!);
  });
}
