/// Models that represent ComfyUI API responses

/// Represents queue information from ComfyUI
class QueueInfo {
  final int queueRunning;
  final List<Map<String, dynamic>> queue;
  final Map<String, dynamic> queuePending;

  QueueInfo({
    required this.queueRunning,
    required this.queue,
    required this.queuePending,
  });

  factory QueueInfo.fromJson(Map<String, dynamic> json) {
    return QueueInfo(
      queueRunning: json['queue_running'] as int,
      queue: List<Map<String, dynamic>>.from(json['queue'] ?? []),
      queuePending: Map<String, dynamic>.from(json['queue_pending'] ?? {}),
    );
  }
}

/// Represents a prompt execution status
class PromptExecutionStatus {
  final String? promptId;
  final int? number;
  final String? status;
  final dynamic error;

  PromptExecutionStatus({
    this.promptId,
    this.number,
    this.status,
    this.error,
  });

  factory PromptExecutionStatus.fromJson(Map<String, dynamic> json) {
    return PromptExecutionStatus(
      promptId: json['prompt_id'] as String?,
      number: json['number'] as int?,
      status: json['status'] as String?,
      error: json['error'],
    );
  }
}

/// Represents history data
class HistoryItem {
  final String promptId;
  final Map<String, dynamic> prompt;
  final Map<String, dynamic>? outputs;

  HistoryItem({
    required this.promptId,
    required this.prompt,
    this.outputs,
  });

  factory HistoryItem.fromJson(Map<String, dynamic> json) {
    return HistoryItem(
      promptId: json['prompt_id'] as String,
      prompt: Map<String, dynamic>.from(json['prompt'] ?? {}),
      outputs: json['outputs'] != null
          ? Map<String, dynamic>.from(json['outputs'])
          : null,
    );
  }
}

/// Represents a progress update received via WebSocket
class ProgressUpdate {
  final String type;
  final Map<String, dynamic> data;

  ProgressUpdate({
    required this.type,
    required this.data,
  });

  factory ProgressUpdate.fromJson(Map<String, dynamic> json) {
    return ProgressUpdate(
      type: json['type'] as String,
      data: Map<String, dynamic>.from(json['data'] ?? {}),
    );
  }
}
