import 'package:dio/dio.dart';
import '../../network_api_service/api_service/api_service.dart';
import '../../network_api_service/api_urls/api_urls.dart';

class SubmitQrCodeRepository {
  final ApiService _apiService = ApiService();

  Future<Map<String, dynamic>> submitQrCode({
    required String qrCode,
  }) async {
    try {
      final response = await _apiService.post(
        ApiUrls.redeem,
        data: {
          "code": qrCode,
        },
        options: Options(
          validateStatus: (status) => status != null && status < 500,
        ),
      );

      return response.data as Map<String, dynamic>;
    } on DioException catch (e) {
      if (e.response?.data != null && e.response?.data is Map<String, dynamic>) {
        return e.response?.data as Map<String, dynamic>;
      }
      rethrow;
    } catch (e) {
      throw Exception('$e');
    }
  }
}