import 'dart:typed_data';
import 'package:fis_ui/index.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_common/event/event_type.dart';
import 'package:flyinsono/architecture/states/states.dart';
import 'package:flyinsono/rpc.dart';
import 'base_manager.dart';
import 'interfaces/entities/single_frame_params.dart';
import 'interfaces/entities/vidImage_parameters.dart';
import 'interfaces/local_rtmp.dart';

class LocalRtmpManager extends BaseManager implements ILocalRtmpManager {
  ///壳子拉流地址的通知
  final onPullUrlNotificationHandler = FEventHandler<String>();

  ///接收到单帧图
  final onSingleFrameImageReceive = FEventHandler<SingleFrameParams>();

  ///截单帧图
  final onCaptureFrame = FEventHandler<bool>();

  ///录制，bool值代表开始or结束
  final onRecord = FEventHandler<bool>();

  ///图像已上传
  final onUploadImage = FEventHandler<VidImageParameters>();

  ///创建检查记录
  Future<bool> createRecordInfo(
      String patientCode, List<DataItemDTO>? patientDatas) async {
    List<PatientInfoExt> patientInfoExt = [];
    patientInfoExt.add(PatientInfoExt(
      content: patientDatas,
    ));
    return await rpc.recordInfo.createForRecordInfoListAsync(
      CreateRecordNewRequest(
        token: token,
        patientCode: patientCode,
        patientDatas: patientDatas,
        //patientInfoExtList: patientInfoExt,
      ),
    );
  }

  Future<bool> createExamData(
    String recordCode, {
    RemedicalFileDataTypeEnum fileDataType =
        RemedicalFileDataTypeEnum.VinnoVidSingle,
    String? previewFileToken,
    String? coverImageToken,
    String? fileToken,
    int fileSize = 0,
  }) async {
    return await rpc.recordInfo.createExamDataAsync(
      CreateExamDataRequest(
        token: token,
        recordCode: recordCode,
        fileDataType: fileDataType,
        previewFileToken: previewFileToken,
        coverImageToken: coverImageToken,
        fileSize: fileSize,
        fileToken: fileToken,
      ),
    );
  }
}
