import 'dart:async';
import 'package:car_customer_app/classes/app_state.dart';
import 'package:car_customer_app/models/m_response.dart';
import 'package:car_customer_app/models/profile/document.dart';
import 'package:car_customer_app/models/user/country.dart';
import 'package:car_customer_app/models/user/role.dart';
import 'package:http/http.dart';
import 'package:car_customer_app/classes/consts.dart';
import 'package:car_customer_app/models/content_info_model.dart';
import 'package:car_customer_app/models/member_model.dart';
import 'package:car_customer_app/models/surah_model.dart';
import 'package:car_customer_app/models/user/basic_otp.dart';
import 'package:car_customer_app/models/user/register_user.dart';

import '../api_client.dart';

class ProfileApiClent {
  static final ProfileApiClent _instance = ProfileApiClent._internal();

  ProfileApiClent._internal();

  factory ProfileApiClent() => _instance;

  Future<Document> getServiceProviderDocument(dynamic userId) async {
    var queryParameters = {
      "ServiceProviderID": userId.toString(),
    };
    String? token = AppState().getUser.data?.accessToken;
    print(token);
    return await ApiClient().getJsonForObject((json) => Document.fromJson(json), ApiConsts.GetProviderDocument, queryParameters: queryParameters, token: AppState().getUser.data!.accessToken ?? "");
  }

  Future<MResponse> serviceProviderDocumentsUpdate(List<DocumentData>? documents) async {
    List<Map<String, dynamic>> map = [];
    for (int i = 0; i < documents!.length; i++) {
      if (documents[i].document != null) {
        var postParams = {
          "id": documents[i].id,
          "serviceProviderID": documents[i].serviceProviderId,
          "documentID": documents[i].documentId,
          "documentExt": documents[i].fileExt,
          "documentImage": documents[i].document,
          "isActive": true
        };
        map.add(postParams);
      }
    }
    String t = AppState().getUser.data!.accessToken ?? "";
    print("tokeen " + t);
    return await ApiClient().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ServiceProviderDocument_Update, map, token: t);
  }
}
