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.List;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
public class DuplicatesFilter implements FlowFunction {

    @Override
    public void apply(CallContext context) {
        var source = context.getSources().getFirst();
        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.setResolveDomains(source.getResolveDomains().stream().distinct().toList());
        context.setOutputs(List.of(output));
    }

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

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

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

    @Override
    public int getInputCount() {
        return 1;
    }

    @Override
    public int getOutputCount() {
        return 1;
    }

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

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

}
