package ru.kirillius.pf.sdn.flow;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ru.kirillius.pf.sdn.api.Networking.NetworkScope;
import ru.kirillius.pf.sdn.api.flow.CallContext;
import ru.kirillius.pf.sdn.api.flow.FlowFunction;
import ru.kirillius.pf.sdn.api.properties.PropertyDescriptor;

import java.util.Collections;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
public class DuplicatesFilter implements FlowFunction {

    @Override
    public void apply(CallContext context) {
        var source = context.getSource();
        var output = new NetworkScope();
        output.setSubnets(source.getSubnets().stream().distinct().toList());
        output.setDomains(source.getDomains().stream().distinct().toList());
        output.setASN(source.getASN().stream().distinct().toList());
        output.setAutoResolvedDomains(source.getAutoResolvedDomains().stream().distinct().toList());
        context.setOutput(output);
    }

    @Override
    public Map<String, PropertyDescriptor> getProperties() {
        return Collections.emptyMap();
    }

    @Override
    public boolean hasInputs() {
        return true;
    }

    @Override
    public boolean hasOutputs() {
        return true;
    }

}
