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

class RaiseTicketRepository {
  final ApiService _apiService = ApiService();

  Future<void> raiseTicket({
    required String subject,
    required String description,
    File? attachment,
  }) async {
    try {
      final Map<String, dynamic> formMap = {
        "subject": subject,
        "description": description,
      };

      if (attachment != null) {
        final fileName = attachment.path.split('/').last;
        formMap["attachment"] = await MultipartFile.fromFile(
          attachment.path,
          filename: fileName,
        );
      }

      final formData = FormData.fromMap(formMap);

      await _apiService.post(
        ApiUrls.supportDetails,
        data: formData,
      );
    } catch (e) {
      rethrow;
    }
  }
}