<?php

namespace App\Integrations\Semrush\Requests;

use App\Integrations\Common\Configurable;
use Exception;

final class GetOrganicOverviewRequest extends Configurable implements RequestInterface
{
    protected $options = [
        'url' => 'https://api.semrush.com/reports/v1/projects/',
        'suffix' => '/tracking',
        'method' => 'GET',
        'action' => 'report',
        'type' => 'tracking_overview_organic',
    ];

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @return string
     */
    public function getMethod(): string
    {
        return $this->getOption('method');
    }

    public function getUri()
    {
        return $this->getOption('url')
            .$this->getOption('projectId')
            .$this->getOption('suffix')
            .'?'
            .http_build_query([
                'action' => $this->getOption('action'),
                'type' => $this->getOption('type'),
                'url' => $this->getOption('reportUrl'),
                'display_limit' => $this->getOption('displayLimit'),
                'key' => $this->getOption('key'),
            ]);
    }

    public function setProjectId(string $projectId)
    {
        $this->setOption('projectId', $projectId);

        return $this;
    }

    /**
     * @return mixed
     *
     * @throws Exception
     */
    public function getProjectId()
    {
        if (null === $this->getOption('projectId')) {
            throw new Exception('Semrush project id is not set');
        }

        return $this->getOption('projectId');
    }

    public function setReportUrl(string $reportUrl)
    {
        $this->setOption('reportUrl', '*.'.$reportUrl.'/*');

        return $this;
    }

    public function getBody()
    {
        return;
    }
}
