import 'package:kmobile/data/models/transfer.dart';
import 'package:dio/dio.dart';

abstract class TransferRepository {
  Future<TransferResponse> transfer(Transfer transfer);
}

class TransferRepositoryImpl implements TransferRepository {
  final Dio _dio;
  TransferRepositoryImpl(this._dio);

  @override
  Future<TransferResponse> transfer(Transfer transfer) async {
    final resp = await _dio.post(
      '/api/payment/transfer',
      data: transfer.toJson(),
    );

    if (resp.statusCode != 200) {
      throw Exception(
        'Error transferring funds: ${resp.statusCode} ${resp.statusMessage}',
      );
    }

    return TransferResponse.fromJson(resp.data as Map<String, dynamic>);
  }
}
