<?php

declare(strict_types=1);

namespace ReallySimplePlugins\RSS\Core\Features\Vulnerability\Services\Strategies;

use ReallySimplePlugins\RSS\Core\Features\Vulnerability\Clients\VulnerabilityClient;
use ReallySimplePlugins\RSS\Core\Features\Vulnerability\Repositories\PluginRepository;

final class PluginSyncStrategy extends AbstractComponentSyncStrategy
{
    private PluginRepository $pluginRepository;
    private VulnerabilityClient $vulnerabilityClient;

    public function __construct(
        PluginRepository    $pluginRepository,
        VulnerabilityClient $vulnerabilityClient
    )
    {
        $this->vulnerabilityClient = $vulnerabilityClient;
        $this->pluginRepository = $pluginRepository;
    }

    /**
     * @inheritDoc
     */
    public function getType(): string
    {
        return 'plugin';
    }

    /**
     * @inheritDoc
     */
    public function getInstalledComponents(): iterable
    {
        return $this->pluginRepository->getInstalledComponents();
    }

    /**
     * @inheritDoc
     */
    protected function fetchFromApi(string $slug, string $name, string $version = ''): array
    {
        return $this->vulnerabilityClient->fetchPlugin($slug, $name);
    }
}
