package ru.kirillius.pf.sdn.flow;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ru.kirillius.pf.sdn.Util.DomainUtil;
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 OverlappedDomainFilter implements FlowFunction {

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

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

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

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

}
