package dev.elaine.datalab.architecture;

public final class ShardRouter {
  private final int shardCount;

  public ShardRouter(int shardCount) {
    if (shardCount <= 0) throw new IllegalArgumentException("shardCount 必须大于 0");
    this.shardCount = shardCount;
  }

  public int shardFor(long userId) {
    return Math.floorMod(Long.hashCode(userId), shardCount);
  }

  public String physicalTable(long userId) {
    return "orders_" + shardFor(userId);
  }
}
