package com.easyagents.federation.sql.federation;

import java.io.Serializable;

/**
 * 一列用于成本估算的轻量统计。
 *
 * @param distinctCount 估算不同值数量；未知时为 0
 * @param nullFraction 空值比例，范围为 0 到 1
 * @param averageWidthBytes 平均列宽字节数；未知时为 0
 */
public record FederationColumnStatistics(
    double distinctCount,
    double nullFraction,
    long averageWidthBytes
) implements Serializable {

    /**
     * 校验列统计。
     */
    public FederationColumnStatistics {
        if (!Double.isFinite(distinctCount) || distinctCount < 0) {
            throw new IllegalArgumentException("distinctCount must be finite and non-negative");
        }
        if (!Double.isFinite(nullFraction) || nullFraction < 0 || nullFraction > 1) {
            throw new IllegalArgumentException("nullFraction must be between 0 and 1");
        }
        if (averageWidthBytes < 0) {
            throw new IllegalArgumentException("averageWidthBytes must be non-negative");
        }
    }
}
