import 'package:oto/oto/application.dart';
import 'package:oto/oto/data/command_data.dart';

class StepEvent {
  final int stepId;
  final int workflowIndex;
  final String stepType;
  final String event;
  final String timestamp;
  final String? commandId;
  final String? commandType;
  final Map<String, String>? error;

  StepEvent({
    required this.stepId,
    required this.workflowIndex,
    required this.stepType,
    required this.event,
    required this.timestamp,
    this.commandId,
    this.commandType,
    this.error,
  });

  Map<String, dynamic> toJson() => {
        'schemaVersion': 1,
        'type': 'stepEvent',
        'event': event,
        'stepId': stepId,
        'workflowIndex': workflowIndex,
        'stepType': stepType,
        'commandId': commandId,
        'commandType': commandType,
        'timestamp': timestamp,
        'error': error,
      };
}

class ExecutionContext {
  DataCommon? commonData;
  Map<String, dynamic> property = {};
  Map<String, CommandState> commandStates = {};
  Map<String, DataCommand> dataCommandMap = {};

  final List<StepEvent> stepEvents = [];
  int _nextStepId = 0;

  int allocateStepEventId() {
    return _nextStepId++;
  }

  void addStepEvent(StepEvent event) {
    stepEvents.add(event);
  }

  void resetStepEvents() {
    stepEvents.clear();
    _nextStepId = 0;
  }
}
