import 'package:flyinsono/lab/components/classify_data_selector/classify_data_model.dart';
import 'package:flyinsono/lab/mock_data/mock_data.dart';
import 'package:fis_measure/interfaces/process/items/item_metas.dart';
import 'package:fis_measure/configs/patient.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_measure/interfaces/process/items/types.dart';

class MockRPC {
  /// 设置网络情况
  static const int rpcDelayMilliseconds = excellent;

  /// 网络延迟预设
  static const int excellent = 50;
  static const int fast = 300;
  static const int slow = 2000;
  static const int bad = 10000;

  /// 获取检查图片列表
  static Future<List<ImageModel>> getImageListByRecordId(
      String recordId) async {
    await Future.delayed(Duration(milliseconds: rpcDelayMilliseconds));
    // TODO mock
    GlobalPatientConfig.height = 80;
    GlobalPatientConfig.weight = 36;
    GlobalPatientConfig.updateBSAbyWH();

    return MockData.demoVidList
        .map((e) => ImageModel(
              id: e.id,
              fileTypeName: e.sampleRemedicalFileDataTypeEnum ==
                      SampleRemedicalFileDataTypeEnum.AnalysisImage
                  ? "URMVRD"
                  : "VRD",
              createTime: DateTime.now(),
              description: (e.id +
                  " " +
                  (e.sampleRemedicalFileDataTypeEnum ==
                          SampleRemedicalFileDataTypeEnum.AnalysisImage
                      ? "URMVRD"
                      : "VRD") +
                  " " +
                  DateTime.now().toString().substring(0, 16)),
              vidDataInfo: e,
              fileDataType: e.sampleRemedicalFileDataTypeEnum,
            ))
        .toList();
  }
}

class ProjectModel extends ClassifyDataBaseModel {
  final String id;
  final ProjectType type;
  final String projectIntroduction;
  final OrganizationPatientTypeEnum organizationPatientType;

  ProjectModel({
    required this.id,
    required this.type,
    required String name,
    required this.projectIntroduction,
    required this.organizationPatientType,
  }) : super(name);
}

enum ProjectType {
  created,
  joined,
}

class PatientModel extends ClassifyDataBaseModel {
  final String id;
  final String fileSize;
  final String code;
  final bool isExistUrmData;

  PatientModel({
    required this.id,
    required this.fileSize,
    required this.code,
    required String name,
    required this.isExistUrmData,
  }) : super(name);
}

class RecordModel {
  final String id;
  final String description;
  final int imageCount;
  final DateTime createTime;
  final List<ImageModel> images;
  final List<DataItemDTO> patientInfo;
  final PatientModel patient;
  final OrganizationPatientTypeEnum organizationPatientTypeEnum;

  RecordModel({
    required this.id,
    required this.description,
    required this.imageCount,
    required this.createTime,
    required this.images,
    required this.patient,
    required this.patientInfo,
    required this.organizationPatientTypeEnum,
  });
}

class ImageModel {
  final String id;
  final String fileTypeName;
  final DateTime createTime;
  final String description;
  final VidDataInfo vidDataInfo;
  final String? urmOriginalCode;

  ///文件类型，单帧或多帧vid、图像、视频
  final SampleRemedicalFileDataTypeEnum fileDataType;
  ImageModel({
    required this.id,
    required this.fileTypeName,
    required this.createTime,
    required this.description,
    required this.vidDataInfo,
    required this.fileDataType,
    this.urmOriginalCode,
  });
}

class VidDataInfo {
  VidDataInfo({
    required this.id,
    required this.vidUrl,
    required this.coverUrl,
    required this.imageType,
    required this.sampleRemedicalFileDataTypeEnum,
    this.extendVidUrls = const [],
  });
  final String id;
  final String vidUrl;
  final String coverUrl;
  final ImageType imageType;
  final SampleRemedicalFileDataTypeEnum sampleRemedicalFileDataTypeEnum;
  final List<String> extendVidUrls;
}

enum ImageType {
  Measure_Result,
  Video,
  URM,
  URM_Result,
  Vid,
}

class MeasureItemInfo {
  ItemMeta itemMeta;
  String description;
  MeasureItemInfo({
    required this.itemMeta,
    required this.description,
  });

  factory MeasureItemInfo.empty() {
    final emptyItem = ItemMeta(
      "EmptyItem",
      measureType: MeasureTypes.Empty,
      description: "",
      outputs: [],
    );
    return MeasureItemInfo(
      itemMeta: emptyItem,
      description: "emptyItem",
    );
  }
}
