package com.atlassian.bitbucket.mesh.network;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collection;

public interface MeshManager {

    /**
     * Retrieves a Mesh node by ID.
     *
     * @param nodeId the node ID
     * @return the matching node, or {@code null} if not found
     */
    @Nullable
    MeshNode findNodeById(@Nonnull String nodeId);

    /**
     * @return the {@link MeshNode} representing this Mesh instance
     */
    @Nonnull
    MeshNode getLocalNode();

    /**
     * Retrieves a Mesh node by ID.
     *
     * @param nodeId the node Id
     * @return the matching node
     * @throws NodeNotFoundException if the node is not known
     */
    @Nonnull
    MeshNode getNodeById(@Nonnull String nodeId);

    /**
     * @return the current members of the cluster
     */
    @Nonnull
    Collection<MeshNode> getNodes();

    /**
     * @param id partition ID
     * @return the matching partition, or {@code null} if the partition is not known
     */
    @Nullable
    Partition getPartition(@Nonnull String id);

    /**
     * @return the possibly empty set of active {@link PartitionReplicaMigration migrations}
     * @since 1.4
     */
    @Nonnull
    Collection<PartitionReplicaMigration> getPartitionMigrations();

    /**
     * @param  partitionId partition ID
     * @return the possibly empty set of active {@link PartitionReplicaMigration migrations} for the partition
     * @since 1.4
     */
    @Nonnull
    Collection<PartitionReplicaMigration> getPartitionMigrations(@Nonnull String partitionId);

    /**
     * @return the configured partitions
     */
    @Nonnull
    Collection<Partition> getPartitions();

    /**
     * Updates the Mesh topology as specified by the provided {@code parameters}.
     *
     * @param parameters describes how the topology should be updated
     */
    void updateTopology(@Nonnull UpdateTopologyParameters parameters);
}
