package dev.elaine.redislab.observe;

public final class CapacityPlanner {
  public Plan estimate(long keyCount, long averageBytesPerKey,
                       double replicationFactor, double headroomRatio) {
    if (keyCount < 0 || averageBytesPerKey < 0 || replicationFactor < 1
        || headroomRatio <= 0 || headroomRatio >= 1) {
      throw new IllegalArgumentException("容量参数不合法");
    }
    long logicalBytes = Math.multiplyExact(keyCount, averageBytesPerKey);
    long provisioned = (long) Math.ceil(logicalBytes * replicationFactor
        / (1 - headroomRatio));
    return new Plan(logicalBytes, provisioned);
  }

  public record Plan(long logicalBytes, long provisionedBytes) {}
}
