import 'dart:async';
import 'package:dart_framework/utils/system_util.dart';
import 'package:oto/oto/application.dart';
import 'package:oto/oto/commands/command.dart';
import 'package:oto/oto/data/command_data.dart';

class BuildDotNet extends Command {
  Function? get error => null;

  @override
  Future execute(DataCommand command) async {
    var data = DataBuildDotNet.fromJson(getParam(command));

    var shell = StringBuffer(getCDPath(workspace));
    shell.write(
        ' $and MSBuild ${data.projectFile} /t:build /p:Configuration=Release;Platform=x86');

    var process = await runtime.start(shell,
        workspace: workspace,
        printStderr: false,
        logHandler: Application.logWithType);

    return await completeProcess(process, command);
  }
}

void registerBuildDotNetCommands() {
  Command.register(
    CommandType.BuildDotNet,
    () => BuildDotNet(),
    spec: const CommandSpec(
      type: CommandType.BuildDotNet,
      category: 'build',
      dataModel: 'DataBuildDotNet',
      samplePath: 'assets/yaml/sample/10_build_tools.yaml',
    ),
  );
}
