package ru.kirillius.pf.sdn.api.Networking;

import lombok.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Container for grouped network identifiers used to configure filtering and subscriptions.
 */
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class NetworkScope {
    @Getter
    @Setter
    private String description = "";
    @Getter
    @Setter
    private List<Integer> ASN = new ArrayList<>();
    @Getter
    @Setter
    private List<IPv4Subnet> subnets = new ArrayList<>();
    @Getter
    @Setter
    private List<String> domains = new ArrayList<>();
    @Getter
    @Setter
    private List<String> resolveDomains = new ArrayList<>();

    public int getResourceCount() {
        return subnets.size() + ASN.size() + domains.size() + resolveDomains.size();
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof NetworkScope that)) return false;
        return Objects.equals(ASN, that.ASN) &&
                Objects.equals(subnets, that.subnets) &&
                Objects.equals(domains, that.domains) &&
                Objects.equals(resolveDomains, that.resolveDomains);
    }

    @Override
    public int hashCode() {
        return Objects.hash(ASN, subnets, domains, resolveDomains);
    }

    /**
     * Clears all stored network identifiers.
     */
    public void clear() {
        ASN.clear();
        subnets.clear();
        domains.clear();
        resolveDomains.clear();
    }

    /**
     * Adds all resources from the provided bundle into this bundle.
     */
    public void add(NetworkScope networkScope) {
        ASN.addAll(networkScope.getASN());
        subnets.addAll(networkScope.getSubnets());
        domains.addAll(networkScope.getDomains());
        resolveDomains.addAll(networkScope.getResolveDomains());
    }

}
