import 'package:fis_common/logger/logger.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:flyinsono/managers/interfaces/report.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/controller/real_time_consultation_controller.dart';
import 'package:flyinsono/views/desktop/real_time_consultation/state.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class RealTimeConsultationReportController {
  final reportManager = Get.find<IReportManager>();
  late final RealTimeConsultationController controller;
  late final RealTimeConsultationState state;

  RealTimeConsultationReportController(
      RealTimeConsultationController controller) {
    this.controller = controller;
    this.state = controller.state;
  }

  Future<List<ReportDTO>> getReportInfoAsync() async {
    try {
      var result =
          await reportManager.findReportsAsync(state.currentConsultationCode);
      state.reportList = result;
      return result;
    } catch (e) {
      logger.e('RealTimeConsultationReportController getFollowUpVisitInfo ex:' +
          e.toString());
      return [];
    }
  }

  /// 格式化时间
  ///
  /// [time] 后端返回的时间
  String getTime(String time) {
    String stringTime = '';
    if (time.isNotEmpty) {
      stringTime = DateFormat("yyyy-MM-dd HH:mm:ss").format(
        DateTime.fromMillisecondsSinceEpoch(
          DateTime.tryParse(time)?.millisecondsSinceEpoch as int,
        ),
      );
    }
    return stringTime;
  }
}
