import 'package:autosos_flutter/api/_api_client.dart';
import 'package:autosos_flutter/model/base_response.dart';
import 'package:autosos_flutter/model/misc.dart';
import 'package:autosos_flutter/service/upload_service.dart';

/// 文件上传 API（七牛凭证获取）
class UploadApi {
  static final UploadApi instance = UploadApi._();
  UploadApi._();

  final _http = ApiClient.instance.http;

  /// 获取七牛上传凭证
  Future<BaseResponse<QiNiuToken>> qiNiuToken() async {
    final r = await _http.get('/v2/upload/qiniu-token');
    return BaseResponse.fromJson(r as Map<String, dynamic>,
        (d) => QiNiuToken.fromJson(d as Map<String, dynamic>));
  }

  /// 通过封装的上传服务上传文件，返回远程 URL
  Future<String> uploadFile(String localPath) async {
    return UploadService.instance.upload(localPath);
  }

  /// 批量上传
  Future<List<String>> uploadFiles(List<String> localPaths) async {
    return UploadService.instance.uploadBatch(localPaths);
  }
}