<?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\ThemeRepository;

final class ThemeSyncStrategy extends AbstractComponentSyncStrategy
{
    private ThemeRepository $themeRepository;
    private VulnerabilityClient $vulnerabilityClient;

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

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

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

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