class ProgressEvent {
  final int value;
  final int max;
  final String promptId;
  final String? node;

  const ProgressEvent({
    required this.value,
    required this.max,
    required this.promptId,
    this.node,
  });

  factory ProgressEvent.fromJson(Map<String, dynamic> json) {
    return ProgressEvent(
      value: json['value'] as int,
      max: json['max'] as int,
      promptId: json['prompt_id'] as String,
      node: json['node'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'value': value,
      'max': max,
      'prompt_id': promptId,
      'node': node,
    };
  }
}

extension ProgressEventComputation on ProgressEvent {
  /// Returns the progress percentage (0-100)
  double get percentage => (value / max) * 100;

  /// Returns true if the progress is complete
  bool get isComplete => value >= max;
}
