<?php

namespace App\Command\Crm\Copyscape;

use App\Integrations\Copyscape\GuzzleHandler;
use App\Integrations\Copyscape\RemainingRequest;
use App\Integrations\Copyscape\RemainingResponse;
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 RemainingCommand extends Command
{
    protected static $defaultName = 'crm:copyscape:remaining';
    /**
     * @var GetApiUnitsRequest
     */
    private $request;
    /**
     * @var GuzzleHandler
     */
    private $handler;

    public function __construct(GuzzleHandler $handler, RemainingRequest $request, ?string $name = null)
    {
        parent::__construct($name);
        $this->request = $request;
        $this->handler = $handler;
    }

    protected function configure()
    {
        $this
            ->setDescription('Get Copyscape remaining credit');
    }

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

        $response = $this->handler->makeRequest($this->request);

        $response = RemainingResponse::from((float) $response->value, (int) $response->today);
        $io->success($response);
    }
}
