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.properties.PropertyDescriptor;

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

@Slf4j
@RequiredArgsConstructor
public class OverlappedDomainFilter extends CommonFunction {

    @Override
    public List<String> getInputNames() {
        return List.of("input");
    }

    @Override
    public List<String> getOutputNames() {
        return List.of("output");
    }

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

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

}
