///|
/// Controls how an in-memory OCF writer groups records into data blocks.
///
/// `max_records` bounds the number of records in one block. `target_bytes`
/// is a soft limit for the uncompressed datum payload: a single record larger
/// than the target is still emitted in its own block as long as it satisfies
/// the hard `OcfLimits.max_block_bytes` bound.
pub struct OcfBlockConfig {
  max_records : Int
  target_bytes : Int
} derive(Debug, Eq)

///|
/// Construct a block policy for multi-block OCF output.
pub fn OcfBlockConfig::new(
  max_records? : Int = 1_000,
  target_bytes? : Int = 256 * 1024,
) -> OcfBlockConfig raise OcfError {
  if max_records <= 0 {
    raise Compression(
      codec="block-config",
      message="max_records must be positive",
    )
  }
  if target_bytes <= 0 {
    raise Compression(
      codec="block-config",
      message="target_bytes must be positive",
    )
  }
  { max_records, target_bytes }
}

///|
/// A balanced default for ordinary in-memory files: at most 1,000 records or
/// approximately 256 KiB of uncompressed payload per data block.
pub fn default_block_config() -> OcfBlockConfig {
  { max_records: 1_000, target_bytes: 256 * 1024 }
}

///|
pub fn OcfBlockConfig::max_records(self : OcfBlockConfig) -> Int {
  self.max_records
}

///|
pub fn OcfBlockConfig::target_bytes(self : OcfBlockConfig) -> Int {
  self.target_bytes
}