import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/my_trakers/blood_sugar/DiabtecPatientResult.dart';
import 'package:diplomaticquarterapp/core/model/my_trakers/blood_sugar/MonthDiabtectResultAverage.dart';
import 'package:diplomaticquarterapp/core/model/my_trakers/blood_sugar/WeekDiabtectResultAverage.dart';
import 'package:diplomaticquarterapp/core/model/my_trakers/blood_sugar/YearDiabtecResultAverage.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';

class BloodSugarService extends BaseService {
  List<MonthDiabtectResultAverage> monthDiabtectResultAverageList = List();
  List<WeekDiabtectResultAverage> weekDiabtectResultAverageList = List();
  List<YearDiabtecResultAverage> yearDiabtecResultAverageList = List();

  ///Result
  List<DiabtecPatientResult> monthDiabtecPatientResult = List();
  List<DiabtecPatientResult> weekDiabtecPatientResult = List();
  List<DiabtecPatientResult> yearDiabtecPatientResult = List();

  Future getBloodSugar() async {
    hasError = false;
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    await baseAppClient.post(GET_DIABETIC_RESULT_AVERAGE,
        onSuccess: (dynamic response, int statusCode) {
      monthDiabtectResultAverageList.clear();
      weekDiabtectResultAverageList.clear();
      yearDiabtecResultAverageList.clear();
      response['List_MonthDiabtectResultAverage'].forEach((item) {
        monthDiabtectResultAverageList
            .add(MonthDiabtectResultAverage.fromJson(item));
      });

      response['List_WeekDiabtectResultAverage'].forEach((item) {
        weekDiabtectResultAverageList
            .add(WeekDiabtectResultAverage.fromJson(item));
      });

      response['List_YearDiabtecResultAverage'].forEach((item) {
        yearDiabtecResultAverageList
            .add(YearDiabtecResultAverage.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future getDiabtecResults() async {
    hasError = false;
    await baseAppClient.post(GET_DIABTEC_RESULT,
        onSuccess: (dynamic response, int statusCode) {
      monthDiabtecPatientResult.clear();
      weekDiabtecPatientResult.clear();
      yearDiabtecPatientResult.clear();

      response['List_MonthDiabtecPatientResult'].forEach((item) {
        monthDiabtecPatientResult.add(DiabtecPatientResult.fromJson(item));
      });

      response['List_WeekDiabtecPatientResult'].forEach((item) {
        weekDiabtecPatientResult.add(DiabtecPatientResult.fromJson(item));
      });

      response['List_YearDiabtecPatientResult'].forEach((item) {
        yearDiabtecPatientResult.add(DiabtecPatientResult.fromJson(item));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: Map());
  }

  addDiabtecResult(
      {String bloodSugerDateChart,
      String bloodSugerResult,
      String diabtecUnit,
      int measuredTime}) async {
    hasError = false;
    super.error = "";

    Map<String, dynamic> body = Map();
    body['BloodSugerDateChart'] = bloodSugerDateChart;
    body['BloodSugerResult'] = bloodSugerResult;
    body['DiabtecUnit'] = diabtecUnit;
    body['MeasuredTime'] =2;// measuredTime;
    body['isDentalAllowedBackend'] = false;

    await baseAppClient.post(ADD_BLOOD_PRESSURE_RESULT,
        onSuccess: (response, statusCode) async {
      var asd ="";
        },
        onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
