/// Client-side view of a Core `task` channel task map.
///
/// Mirrors the implemented `task.list`/`task.get`/`task.enqueue` response shape
/// described in `packages/contracts/notes/flutter-core-api-candidates.md`. The
/// model stays tolerant of missing optional fields so partial task maps returned
/// by different actions still parse.
class WorkspaceTask {
  final String id;
  final String title;
  final String status;
  final String source;
  final String? error;

  const WorkspaceTask({
    required this.id,
    required this.title,
    required this.status,
    required this.source,
    this.error,
  });

  factory WorkspaceTask.fromMap(Map<String, Object?> map) {
    return WorkspaceTask(
      id: map['id'] as String? ?? '',
      title: map['title'] as String? ?? 'Untitled task',
      status: map['status'] as String? ?? 'unknown',
      source: map['source'] as String? ?? '',
      error: map['error'] as String?,
    );
  }
}
