<?php
namespace Incoviba\Command\Money;

use DateTimeImmutable;
use Symfony\Component\Console;
use Incoviba\Common\Alias\Command;

#[Console\Attribute\AsCommand(
    name: 'money:uf',
    description: 'Get the UF value for today'
)]
class UF extends Command
{
    public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
    {
        $this->logger->debug("Running {$this->getName()}");
        $now = new DateTimeImmutable();
        $uri = '/api/money/uf';
        $data = [
            'fecha' => $now->format('Y-m-d')
        ];
        $output->writeln("POST {$uri}");
        $response = $this->client->post($uri, [
            'body' => http_build_query($data),
            'headers' => ['Content-Type' => 'application/x-www-form-urlencoded']
        ]);
        $output->writeln("Response Code: {$response->getStatusCode()}");
        return Console\Command\Command::SUCCESS;
    }
}
