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/branch.dart';
import 'package:car_customer_app/models/profile/categroy.dart';
import 'package:car_customer_app/models/profile/document.dart';
import 'package:car_customer_app/models/profile/services.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 BranchApiClent {
  static final BranchApiClent _instance = BranchApiClent._internal();

  BranchApiClent._internal();

  factory BranchApiClent() => _instance;

  Future<MResponse> createBranch(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude) async {
    var postParams = {
      // "id": 0,
      "serviceProviderID": AppState().getUser.data?.userInfo?.providerId ?? "",
      "branchName": branchName,
      "branchDescription": branchDescription,
      "cityID": cityId,
      "address": address,
      "latitude": latitude,
      "longitude": longitude,
      "isActive": true
    };
    String t = AppState().getUser.data!.accessToken ?? "";
    print("tokeen " + t);
    return await ApiClient().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createProviderBranch, postParams, token: t);
  }

  Future<Branch> fetchAllBranches() async {
    var postParams = {"ServiceProviderID": AppState().getUser.data?.userInfo?.providerId.toString() ?? ""};
    String t = AppState().getUser.data!.accessToken ?? "";
    print("tokeen " + t);
    return await ApiClient().getJsonForObject((json) => Branch.fromJson(json), ApiConsts.ServiceProviderBranchGet, queryParameters: postParams, token: t);
  }

  Future<Category> fetchBranchCategory() async {
    var postParams = {"ServiceProviderID": AppState().getUser.data?.userInfo?.providerId.toString() ?? ""};
    String t = AppState().getUser.data!.accessToken ?? "";
    print("tokeen " + t);
    return await ApiClient().getJsonForObject((json) => Category.fromJson(json), ApiConsts.ServiceCategory_Get, queryParameters: postParams, token: t);
  }

  Future<Services> fetchServices(String serviceCategoryId) async {
    var postParams = {"ServiceCategoryID": serviceCategoryId};
    String t = AppState().getUser.data!.accessToken ?? "";
    print("tokeen " + t);
    return await ApiClient().getJsonForObject((json) => Services.fromJson(json), ApiConsts.Services_Get, queryParameters: postParams, token: t);
  }

  Future<MResponse> createService(List<Map<String, dynamic>> map) async {
    String t = AppState().getUser.data!.accessToken ?? "";
    return await ApiClient().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ServiceProviderService_Create, map, token: t);
  }
}
