// Repository Impl

import 'package:dio/dio.dart';
import 'package:networks_sdk/src/data/dto/api_requestable.dart';
import 'package:networks_sdk/src/presentation/wiring/api_config.dart';
import 'package:networks_sdk/src/presentation/wiring/network_callbacks.dart';

import '../../domain/repositories/networks_sdk_repository.dart';
import '../datasources/networks_sdk_method_channel_datasource.dart';

/// [NetworksSdkRepository] 的实现，透传给 [NetworksSdkMethodChannelDataSource]
class NetworksSdkRepositoryImpl implements NetworksSdkRepository {
  final NetworksSdkMethodChannelDataSource _datasource;

  const NetworksSdkRepositoryImpl(this._datasource);

  @override
  Future<String?> platformVersion() {
    return _datasource.getPlatformVersion();
  }

  @override
  void initialize(ApiConfig apiConfig) {
    _datasource.initialize(apiConfig);
  }

  @override
  Future<T?> executeRequest<T>(
    ApiRequestable<T> request, {
    CancelToken? cancelToken,
  }) {
    return _datasource.executeRequest(request, cancelToken: cancelToken);
  }

  @override
  Future<void> executeDownload({
    required String url,
    required String savePath,
    OnDownloadProgress? onProgress,
    CancelToken? cancelToken,
    bool resume = false,
    Map<String, String>? headers,
  }) {
    return _datasource.executeDownload(
      url: url,
      savePath: savePath,
      onProgress: onProgress,
      cancelToken: cancelToken,
      resume: resume,
      headers: headers,
    );
  }
}
