import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/procedure/categories_procedure.dart';
import 'package:doctor_app_flutter/core/model/procedure/get_ordered_procedure_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/get_ordered_procedure_request_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/get_procedure_req_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/procedure_valadate_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/procedure_valadate_request_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/update_procedure_request_model.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';

class ProcedureService extends BaseService {
  List<GetOrderedProcedureModel> _procedureList = List();
  List<GetOrderedProcedureModel> get procedureList => _procedureList;
  List<ProcedureValadteModel> _valadteProcedureList = List();
  List<ProcedureValadteModel> get valadteProcedureList => _valadteProcedureList;
  List<CategoriseProcedureModel> _categoriesList = List();
  List<CategoriseProcedureModel> get categoriesList => _categoriesList;
  List<Procedures> procedureslist = List();
  List<dynamic> categoryList = [];

  GetOrderedProcedureRequestModel _getOrderedProcedureRequestModel =
      GetOrderedProcedureRequestModel();

  GetProcedureReqModel _getProcedureReqModel = GetProcedureReqModel(
      // clinicId: 17,
      // pageSize: 10,
      // pageIndex: 1,
      // //patientMRN: 3120725,
      // //categoryId: null,
      // vidaAuthTokenID:
      //     "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxNDg1IiwianRpIjoiZjQ4YTk0OTQtYTczZS00MDI3LWI2MjgtNzc4MjAwMzUyYWEzIiwiZW1haWwiOiJNb2hhbWVkLlJlc3dhbkBjbG91ZHNvbHV0aW9uLXNhLmNvbSIsImlkIjoiMTQ4NSIsIk5hbWUiOiJTSEFLRVJBIFBBUlZFRU4gKFVTRUQgQlkgRVNFUlZJQ0VTKSIsIkVtcGxveWVlSWQiOiIxNDg1IiwiRmFjaWxpdHlHcm91cElkIjoiMDEwMjY2IiwiRmFjaWxpdHlJZCI6IjE1IiwiUGhhcmFtY3lGYWNpbGl0eUlkIjoiNTUiLCJJU19QSEFSTUFDWV9DT05ORUNURUQiOiJUcnVlIiwiRG9jdG9ySWQiOiIxNDg1IiwiU0VTU0lPTklEIjoiMjE1ODUyMTAiLCJDbGluaWNJZCI6IjMiLCJyb2xlIjoiRE9DVE9SUyIsIm5iZiI6MTYwODM2NDU2OCwiZXhwIjoxNjA5MjI4NTY4LCJpYXQiOjE2MDgzNjQ1Njh9.YLbvq5nxPn8o9ZYkcbc5YAX7Jy23Mm0s33oRmE8GHDI",
      //
      // search: ["lab"],
      );

  GetProcedureReqModel _getProcedureCategoriseReqModel = GetProcedureReqModel(
    clinicId: 0,
    pageSize: 100,
    pageIndex: 1,
    patientMRN: 0,
    //categoryId: null,
    vidaAuthTokenID:
        "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxNDg1IiwianRpIjoiZjQ4YTk0OTQtYTczZS00MDI3LWI2MjgtNzc4MjAwMzUyYWEzIiwiZW1haWwiOiJNb2hhbWVkLlJlc3dhbkBjbG91ZHNvbHV0aW9uLXNhLmNvbSIsImlkIjoiMTQ4NSIsIk5hbWUiOiJTSEFLRVJBIFBBUlZFRU4gKFVTRUQgQlkgRVNFUlZJQ0VTKSIsIkVtcGxveWVlSWQiOiIxNDg1IiwiRmFjaWxpdHlHcm91cElkIjoiMDEwMjY2IiwiRmFjaWxpdHlJZCI6IjE1IiwiUGhhcmFtY3lGYWNpbGl0eUlkIjoiNTUiLCJJU19QSEFSTUFDWV9DT05ORUNURUQiOiJUcnVlIiwiRG9jdG9ySWQiOiIxNDg1IiwiU0VTU0lPTklEIjoiMjE1ODUyMTAiLCJDbGluaWNJZCI6IjMiLCJyb2xlIjoiRE9DVE9SUyIsIm5iZiI6MTYwODM2NDU2OCwiZXhwIjoxNjA5MjI4NTY4LCJpYXQiOjE2MDgzNjQ1Njh9.YLbvq5nxPn8o9ZYkcbc5YAX7Jy23Mm0s33oRmE8GHDI",

    //search: ["DENTAL"],
  );

  Future getProcedure({int mrn}) async {
    _getOrderedProcedureRequestModel =
        GetOrderedProcedureRequestModel(patientMRN: mrn);
    hasError = false;
    _procedureList.clear();
    await baseAppClient.post(GET_PROCEDURE_LIST,
        onSuccess: (dynamic response, int statusCode) {
      _procedureList.add(
          GetOrderedProcedureModel.fromJson(response['OrderedProcedureList']));
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _getOrderedProcedureRequestModel.toJson());
  }

  Future getCategory() async {
    hasError = false;

    await baseAppClient.post(GET_LIST_CATEGORISE,
        onSuccess: (dynamic response, int statusCode) {
      categoryList = [];
      categoryList = response['listProcedureCategories']['entityList'];
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: Map());
  }

  Future getProcedureCategory({String categoryName, String categoryID}) async {
    _getProcedureCategoriseReqModel = GetProcedureReqModel(
      search: [categoryName],
      patientMRN: 0,
      pageIndex: 0,
      clinicId: 0,
      pageSize: 0,
      category: categoryID ?? "01",
    );
    hasError = false;
    _categoriesList.clear();
    await baseAppClient.post(GET_CATEGORISE_PROCEDURE,
        onSuccess: (dynamic response, int statusCode) {
      _categoriesList
          .add(CategoriseProcedureModel.fromJson(response['ProcedureList']));
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _getProcedureCategoriseReqModel.toJson());
  }

  Future postProcedure(PostProcedureReqModel postProcedureReqModel) async {
    hasError = false;
    _procedureList.clear();
    await baseAppClient.post(POST_PROCEDURE_LIST,
        onSuccess: (dynamic response, int statusCode) {
      print("Success");
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: postProcedureReqModel.toJson());
  }

  Future updateProcedure(
      UpdateProcedureRequestModel updateProcedureRequestModel) async {
    hasError = false;
    _procedureList.clear();
    await baseAppClient.post(UPDATE_PROCEDURE,
        onSuccess: (dynamic response, int statusCode) {
      print("ACCEPTED");
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: updateProcedureRequestModel.toJson());
  }

  Future valadteProcedure(
      ProcedureValadteRequestModel procedureValadteRequestModel) async {
    hasError = false;
    _valadteProcedureList.clear();
    await baseAppClient.post(GET_PROCEDURE_VALIDATION,
        onSuccess: (dynamic response, int statusCode) {
      _valadteProcedureList.add(
          ProcedureValadteModel.fromJson(response['ValidateProcedureList']));
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: procedureValadteRequestModel.toJson());
  }
}
