import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart';
import 'package:diplomaticquarterapp/models/Request.dart';
import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:flutter/material.dart';

class CovidDriveThruService extends BaseService {
  AppSharedPreferences sharedPref = AppSharedPreferences();
  AppGlobal appGlobal = new AppGlobal();

  AuthenticatedUser authUser = new AuthenticatedUser();
  AuthProvider authProvider = new AuthProvider();

  Future<Map> getCovidProjectsList(BuildContext context) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    request = {};

    dynamic localRes;

    await baseAppClient.post(GET_COVID_DRIVETHRU_PROJECT_LIST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getCovidTestProceduresList(BuildContext context, num testTypeEnum, num testProcedureEnum, int projectID) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }
    request = {
      "ProjectID": projectID,
      "TestTypeEnum": testTypeEnum,
      "TestProcedureEnum": testProcedureEnum
    };

    dynamic localRes;

    await baseAppClient.post(GET_COVID_DRIVETHRU_PROCEDURES_LIST, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getCovidPaymentInformation(BuildContext context, int projectID, String procedureID, num testTypeEnum, num testProcedureEnum) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    request = {
      "ProjectID": projectID,
      "ProcedureId": procedureID,
      "TestTypeEnum": testTypeEnum,
      "TestProcedureEnum": testProcedureEnum
    };

    dynamic localRes;

    await baseAppClient.post(GET_COVID_DRIVETHRU_PAYMENT_INFO, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }

  Future<Map> getCovidFreeSlots(BuildContext context, int projectID, num testTypeEnum, num testProcedureEnum) async {
    Map<String, dynamic> request;

    if (await this.sharedPref.getObject(USER_PROFILE) != null) {
      var data = AuthenticatedUser.fromJson(await this.sharedPref.getObject(USER_PROFILE));
      authUser = data;
    }

    request = {
      "ProjectID": projectID,
      "TestTypeEnum": testTypeEnum,
      "TestProcedureEnum": testProcedureEnum
    };

    dynamic localRes;

    await baseAppClient.post(GET_COVID_DRIVETHRU_FREE_SLOTS, onSuccess: (response, statusCode) async {
      localRes = response;
    }, onFailure: (String error, int statusCode) {
      throw error;
    }, body: request);
    return Future.value(localRes);
  }
}
