<?php

namespace App\Commands;

use App\Services\Command;
use App\Services\Docker;
use Illuminate\Process\Pipe;
use Illuminate\Support\Facades\Process;

class Dev extends Command
{
    protected $signature = 'dev';
    protected $description = 'Get the development environment up and running';

    public function handle() : void
    {

        $this->info('Starting Development Environment');
        
        $upCommand = Docker::base('up -d');
        $binCommand = Docker::bin('dev');


        Process::pipe(static function (Pipe $pipe) use ($upCommand, $binCommand) {
            $pipe->as('up')->command($upCommand);
            $pipe->as('vite')->forever()->tty()->command($binCommand);
        }, function (string $type, string $output, string $key) {
            $this->line(sprintf('[%s] %s', $key, $output));
        });
    }
}
