Documentation
// Copyright (c) 2026, Salesforce, Inc.,
// All rights reserved.
// For full license text, see the LICENSE.txt file

use crate::host::property::PropertyAccessor;
use log::debug;

const BUFFER_SIZE: &[&str] = &[
    "node",
    "metadata",
    "flex_env",
    "FLEX_DOWNSTREAM_CONNECTION_BUFFER_LIMIT_BYTES",
];

pub(crate) struct BufferSize;

impl BufferSize {
    pub fn set_max_body(property_accessor: &dyn PropertyAccessor) {
        if !classy::hl::__internal::__buffer_size_set() {
            let size: Option<usize> = property_accessor
                .read_property(BUFFER_SIZE)
                .filter(|bytes| !bytes.is_empty())
                .and_then(|bytes| String::from_utf8_lossy(&bytes).parse().ok());

            debug!("Setting buffer size to {size:?}");
            classy::hl::__internal::__set_buffer_size(size);
        }
    }
}