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

class RtgsService {
  final Dio _dio;

  RtgsService(this._dio);

  Future<RtgsResponse> processRtgsTransaction(
      RtgsTransaction transaction) async {
    try {
      await Future.delayed(const Duration(seconds: 3));
      final response = await _dio.post(
        '/api/payment/rtgs',
        data: transaction.toJson(),
      );

      if (response.statusCode == 200) {
        return RtgsResponse.fromJson(response.data);
      } else {
        throw Exception(
            'RTGS transaction failed with status code: ${response.statusCode}');
      }
    } on DioException {
      rethrow;
    } catch (e) {
      throw Exception('An unexpected error occurred: ${e.toString()}');
    }
  }
}
