import 'dart:io';
import 'package:yumi/shared/business_logic/repositories/general_repository.dart';
import 'package:yumi/shared/data_sources/sources/remote/net/api.dart';
import 'package:yumi/shared/data_sources/sources/remote/net/network_client.dart';

class SCGeneralRepositoryImp implements SocialChatGeneralRepository {
  static SCGeneralRepositoryImp? _instance;

  SCGeneralRepositoryImp._internal();

  factory SCGeneralRepositoryImp() {
    return _instance ??= SCGeneralRepositoryImp._internal();
  }

  ///external/oss/upload
  @override
  Future<String> upload(File image) async {
    String filePath = image.path;
    var name =
        filePath.substring(filePath.lastIndexOf("/") + 1, filePath.length);
    FormData formData = FormData.fromMap(
      {"file": await MultipartFile.fromFile(filePath, filename: name)},
    );
    final response = await http.dio.post(
      "91458261d1ab337ad7b1da3610dd496cf7f58dbb0fecacfbdfe516c4892b1694",
      data: formData,
      options: Options(
        contentType: 'multipart/form-data',
        sendTimeout: const Duration(seconds: 60),
        receiveTimeout: const Duration(seconds: 60),
        extra: {
          TimeOutInterceptor.timeoutSecondsKey: 60,
        },
      ),
    );
    final baseResponse = ResponseData<String>.fromJson(
      response.data as Map<String, dynamic>,
      fromJsonT: (json) => json as String,
    );
    return baseResponse.body ?? "";
  }
}
