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

import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ru.kirillius.pf.sdn.entity.SubscriptionProviderConfig;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Builder
public class SubscriptionProvider {
    private final SubscriptionProviderProtocol protocol;
    private final SubscriptionProviderConfig config;

    public List<Subscription> getSubscriptions() {
        return Collections.unmodifiableList(subscriptions);
    }

    private final List<Subscription> subscriptions = new ArrayList<>();

    public List<Subscription> update() {
        var result = protocol.query(config);
        subscriptions.clear();
        subscriptions.addAll(result.subscriptions());
        return result.updated();
    }

}
