package ru.kirillius.pf.sdn.flow;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ru.kirillius.pf.sdn.Util.IPv4Util;
import ru.kirillius.pf.sdn.api.Networking.NetworkScope;
import ru.kirillius.pf.sdn.api.flow.CallContext;

import java.util.List;

@Slf4j
@RequiredArgsConstructor
public class MergeNeighbourSubnetFilter 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(IPv4Util.mergeNeighbours(source.getSubnets()));
        output.setDomains(source.getDomains());
        output.setASN(source.getASN());
        output.setResolveDomains(source.getResolveDomains());
        context.setOutputs(List.of(output));
    }

}
