class ColumnMaxAndPrefixSizesMatch implements AISValidation {

    @Override
    public void validate(AkibanInformationSchema ais, AISValidationOutput output) {
        for(Table table : ais.getTables().values()) {
            for(Column column : table.getColumnsIncludingInternal()) {
                Long maxStorage = column.getMaxStorageSize();
                Long computedMaxStorage = column.computeStorageSize(false);
                Integer prefix = column.getPrefixSize();
                Integer computedPrefix = column.computePrefixSize();
                if((maxStorage != null) && !maxStorage.equals(computedMaxStorage)) {
                    output.reportFailure(new AISValidationFailure(
                            new ColumnSizeMismatchException(table.getName(), column.getName(),
                                                            "maxStorageSize", maxStorage, computedMaxStorage)
                    ));
                }
                if((prefix != null) && !prefix.equals(computedPrefix)) {
                    output.reportFailure(new AISValidationFailure(
                            new ColumnSizeMismatchException(table.getName(), column.getName(),
                                                            "prefixSize", prefix, computedPrefix)
                    ));
                }
            }
        }
    }

}