import 'package:recording_tool/features/recording/model/model_clipboard.dart';
import 'package:recording_tool/features/recording/model/model_recording_session.dart';

class RecordingModel {
  /// 剪切板内容
  final ClipboardRecordingModel clipboardRecordingModel;

  /// 剪切板是否包含有效的小程序录制信息
  final bool hasValidClipboardInfo;

  /// 录制会话状态
  final RecordingSessionState session;

  RecordingModel({
    required this.clipboardRecordingModel,
    this.hasValidClipboardInfo = false,
    this.session = const RecordingSessionState(),
  });

  bool get isRecording => session.isRecording;

  factory RecordingModel.fromJson(Map<String, dynamic> json) {
    return RecordingModel(
      clipboardRecordingModel: ClipboardRecordingModel.fromJson(
        json['clipboardRecordingModel'],
      ),
    );
  }
  Map<String, dynamic> toJson() {
    return {'clipboardRecordingModel': clipboardRecordingModel.toJson()};
  }

  /// 剪切板是否包含可用于命名的 [ClipboardRecordingModel.filename]。
  bool get hasClipboardFilename {
    final name = clipboardRecordingModel.filename?.trim();
    return hasValidClipboardInfo && name != null && name.isNotEmpty;
  }

  RecordingModel copyWith({
    ClipboardRecordingModel? clipboardRecordingModel,
    bool? hasValidClipboardInfo,
    RecordingSessionState? session,
  }) {
    return RecordingModel(
      clipboardRecordingModel:
          clipboardRecordingModel ?? this.clipboardRecordingModel,
      hasValidClipboardInfo:
          hasValidClipboardInfo ?? this.hasValidClipboardInfo,
      session: session ?? this.session,
    );
  }
}
