import 'package:fis_jsonrpc/rpc.dart';
import 'package:vnoteapp/managers/interfaces/follow_up.dart';
import 'package:vnoteapp/rpc.dart';
import 'package:vnoteapp/store/store.dart';
import 'package:fis_common/logger/logger.dart';

class FollowUpManager implements IFollowUpManager {
  @override
  Future<String> createFollowUp(CreateFollowUpRequest examRequest) async {
    try {
      examRequest.token = Store.user.token;
      final examCode = await rpc.followUp.createFollowUpAsync(
        examRequest,
      );
      return examCode;
    } catch (e) {
      logger.e("DoctorManager sync user info error.", e);
      return '';
    }
  }

  @override
  Future<List<FollowUpDTO>?> getFollowUpPage(
      FollowUpPageRequest followUpPageRequest) async {
    try {
      followUpPageRequest.token = Store.user.token;
      final result = await rpc.followUp.getFollowUpPageAsync(
        followUpPageRequest,
      );
      return result.pageData;
    } catch (e) {
      logger.e("DoctorManager sync user info error.", e);
      return null;
    }
  }

  @override
  Future<List<FollowUpRecordDTO>?> getFollowUpRecordList(List<String> keys,
      String patientCode) async {
    try {
      var request = GetFollowUpRecordListRequest(
          keys: keys, patientCode: patientCode, token: Store.user.token);
      final result = await rpc.followUp.getFollowUpRecordListAsync(request);
      return result;
    } catch (e) {
      return null;
    }
  }
}
