import 'package:oto/oto/core/execution_context.dart';

class BuildResult {
  final bool success;
  final int exitCode;
  final Object? error;
  final StackTrace? stackTrace;
  final List<StepEvent> stepEvents;

  const BuildResult.success({this.stepEvents = const []})
      : success = true,
        exitCode = 0,
        error = null,
        stackTrace = null;

  const BuildResult.failure(this.error, this.stackTrace, {this.exitCode = 10, this.stepEvents = const []})
      : success = false;

  String get message => success
      ? 'Build completed successfully.'
      : (error?.toString() ?? 'Build failed.');

  Map<String, dynamic> toJson() => {
        'schemaVersion': 1,
        'type': 'executionResult',
        'success': success,
        'exitCode': exitCode,
        'message': message,
        'error': success
            ? null
            : {
                'type': error.runtimeType.toString(),
                'message': message,
              },
        'stepEvents': stepEvents.map((e) => e.toJson()).toList(),
      };
}


