import 'package:dio/dio.dart';

import '../../models/admin_quarantine_item.dart';

class AdminQuarantineApi {
  AdminQuarantineApi(this._dio);
  final Dio _dio;

  /// GET /api/admin/quarantine — flat list (no envelope) of aggregated
  /// quarantine rows.
  Future<List<AdminQuarantineItem>> list() async {
    final r = await _dio.get<List<dynamic>>('/api/admin/quarantine');
    final raw = r.data ?? const [];
    return raw
        .map((e) =>
            AdminQuarantineItem.fromJson((e as Map).cast<String, dynamic>()))
        .toList(growable: false);
  }

  Future<void> resolve(String trackId) async {
    await _dio.post<void>('/api/admin/quarantine/$trackId/resolve');
  }

  Future<void> deleteFile(String trackId) async {
    await _dio.post<void>('/api/admin/quarantine/$trackId/delete-file');
  }

  Future<void> deleteViaLidarr(String trackId) async {
    await _dio.post<void>('/api/admin/quarantine/$trackId/delete-via-lidarr');
  }
}
