import 'package:mitra_corporate/model/registration_filter_model.dart';
import 'package:mitra_corporate/model/registration_model.dart';
import 'package:mitra_corporate/model/test_model.dart';

import '../app/constant.dart';
import 'base_repository.dart';

class RegistrationRepository extends BaseRepository {
  RegistrationRepository({required super.dio});

  Future<List<TestModel>> getFPP({
    required String mouID,
    required String token,
  }) async {
    var param = {"mou_id": mouID, "token": token};
    // print(param);
    final url = "${Constant.baseUrl}fpp/load";
    final resp = await post(param: param, service: url);
    List<TestModel> data;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      data = [];
      resp['data'].forEach((e) {
        final model = TestModel.fromJson(e);
        data.add(model);
      });
    } else {
      data = [];
    }

    return data;
  }

  Future<RegistrationFilterModel> getFilter({
    required String token,
  }) async {
    var param = {"token": token};
    final url = "${Constant.baseUrl}Registration/getfilter";
    final resp = await post(param: param, service: url);
    RegistrationFilterModel data;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      data = RegistrationFilterModel.fromJson(resp['data']);
    } else {
      data = RegistrationFilterModel();
    }

    return data;
  }

  Future<List<GetSpecimenModel>> getSpecimen({
    required String token,
    required List<Map<String, String>> arrTest,
  }) async {
    var param = {"token": token, "arr_test": arrTest};
    final url = "${Constant.baseUrl}Registration/getsampletype";
    final resp = await post(param: param, service: url);
    List<GetSpecimenModel> data;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      data = [];
      resp['data'].forEach((e) {
        final model = GetSpecimenModel.fromJson(e);
        data.add(model);
      });
    } else {
      data = [];
    }

    return data;
  }

  Future<String> addOrder({required RegistrationModel prm}) async {
    final url = "${Constant.baseUrl}Registration/addpatient";
    final resp = await post(param: prm.toJson(), service: url);
    String number;
    // print(resp['data']);
    if (resp['status'] == 'OK') {
      number = resp['data']['orderNumber'];
    } else {
      number = "";
    }

    return number;
  }
}
