package ru.kirillius.pf.sdn.api.Networking.Subscriptions;

import lombok.RequiredArgsConstructor;
import ru.kirillius.pf.sdn.entity.SubscriptionProviderConfig;
import ru.kirillius.pf.sdn.repository.SubscriptionCacheRepository;

import java.util.Collections;

@RequiredArgsConstructor
public class CacheFallbackProviderProtocol implements SubscriptionProviderProtocol {
    @Override
    public String getIdentifier() {
        return "Fallback:cache";
    }

    @Override
    public PropertyCollection getProperties() {
        return new PropertyCollection();
    }

    private final SubscriptionCacheRepository cacheRepository;

    @Override
    public SubscriptionQueryResult query(SubscriptionProviderConfig config) {
        var found = cacheRepository.getAllByNameStartsWith(config.getName());
        return new SubscriptionQueryResult(Collections.unmodifiableList(found), Collections.emptyList());
    }
}
