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

final class CoreSyncStrategy extends AbstractComponentSyncStrategy
{
    private CoreRepository $coreRepository;
    private VulnerabilityClient $vulnerabilityClient;

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

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

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

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