<?php

namespace App\Command;

use App\Repository\OrderRepository;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use App\Helper\Hiltes;

#[AsCommand(
    name: 'hiltes:export',
    description: 'Erstellt die Hiltes-Exportdatei aus den aktuellen Bestelldaten',
)]
class HiltesExportCommand extends Command
{
    public function __construct(OrderRepository $orderRepository, LoggerInterface $logger, private Hiltes $hiltes)
    {
      $this->orderRepository = $orderRepository;
      $this->logger = $logger;

      parent::__construct();
    }


    protected function configure(): void
    {
        $this
            ->addArgument('arg1', InputArgument::OPTIONAL, 'Argument description')
            ->addOption('option1', null, InputOption::VALUE_NONE, 'Option description')
        ;
    }

    /**
     * Schreibt die Hiltes Expport Datei
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);

        $io->info('Start Hiltes Export');



        $orders = $this->orderRepository->findAll();

        dump($orders);

        foreach ($orders as $order) {
          $this->hiltes->addOrder($order);
        }


        $this->hiltes->export('Test Test');


        $io->success('Done!');

        return Command::SUCCESS;
    }
}