<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

class SimulationController extends AbstractController
{
    #[Route('/simulation', name: 'simulation')]
    public function index(): Response
    {
        return $this->render('simulation/index.html.twig', [
            'controller_name' => 'SimulationController',
        ]);
    }
    #[Route('/simulate', name: 'run_simulation')]
    public function simulate(): Response
    {
			$process1 = new Process(['python3', 'python/simulation.py']);
			//$process = new Process(['cat', 'python/graph.dot']);
			$process1->run();
			//$process->run();

			// executes after the command finishes
			if (!$process1->isSuccessful()) {
					throw new ProcessFailedException($process1);
			}

			$output = $process1->getOutput();
			$response = new Response($output);
			return $response;
    }
}
