<?php

declare(strict_types=1);

namespace App\Framework\Console\Examples;

use App\Framework\Console\ConsoleCommand;
use App\Framework\Console\ConsoleInput;
use App\Framework\Console\ConsoleOutput;
use App\Framework\Console\ProgressBar;
use App\Framework\Core\ValueObjects\Duration;
use App\Framework\DateTime\Timer;

class ProgressBarExample
{
    public function __construct(
        private readonly Timer $timer
    ) {
    }

    #[ConsoleCommand(name: 'demo:progressbar', description: 'Zeigt eine Demonstration der Fortschrittsanzeige')]
    public function showProgressBarDemo(ConsoleInput $input, ConsoleOutput $output): int
    {
        $output->writeInfo('Demonstration der Fortschrittsanzeige');
        $output->newLine();

        // Einfache Fortschrittsanzeige
        $output->writeLine('Einfache Fortschrittsanzeige:');
        $progress = new ProgressBar($output, 10);
        $progress->start();

        for ($i = 0; $i < 10; $i++) {
            // Simuliere Arbeit
            $this->timer->sleep(Duration::fromMilliseconds(200));
            $progress->advance();
        }

        $progress->finish();

        // Fortschrittsanzeige mit angepasstem Format
        $output->writeLine('Fortschrittsanzeige mit angepasstem Format:');
        $progress = new ProgressBar($output, 5);
        $progress->setFormat('%bar% %current%/%total% [%percent%%] - %elapsed%s vergangen, %remaining%s verbleibend');
        $progress->setBarCharacters('█', '░', '█');
        $progress->start();

        for ($i = 0; $i < 5; $i++) {
            // Simuliere Arbeit
            $this->timer->sleep(Duration::fromMilliseconds(500));
            $progress->advance();
        }

        $progress->finish();

        $output->writeSuccess('Demonstration abgeschlossen!');

        return 0;
    }
}
