import 'package:dio/dio.dart';

import '../../models/admin_request.dart';

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

  /// GET /api/admin/requests — flat list of pending requests.
  /// Server defaults to ?status=pending; we don't override.
  Future<List<AdminRequest>> list() async {
    final r = await _dio.get<List<dynamic>>('/api/admin/requests');
    final raw = r.data ?? const [];
    return raw
        .map((e) => AdminRequest.fromJson((e as Map).cast<String, dynamic>()))
        .toList(growable: false);
  }

  Future<void> approve(String id) async {
    await _dio.post<void>('/api/admin/requests/$id/approve');
  }

  Future<void> reject(String id) async {
    await _dio.post<void>('/api/admin/requests/$id/reject');
  }
}
