<?php

namespace App\Command\Crm\Semrush;

use App\Integrations\Semrush\Client;
use App\Integrations\Semrush\Requests\GetApiUnitsRequest;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class UnitsCommand extends Command
{
    protected static $defaultName = 'crm:semrush:units';
    /**
     * @var GetApiUnitsRequest
     */
    private $request;
    /**
     * @var Client
     */
    private $client;

    public function __construct(Client $client, GetApiUnitsRequest $request, ?string $name = null)
    {
        parent::__construct($name);
        $this->request = $request;
        $this->client = $client;
    }

    protected function configure()
    {
        $this
            ->setDescription('Get SEMrush API units number');
    }

    /**
     * @return void
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);

        $response = $this->client->execute($this->request);

        $io->success(sprintf('There is %d available API units', $response->getBody()));
    }
}
