use std::sync::Arc;

use crate::tracking::trackable::TrackingStateCell;

pub(crate) struct TrackingData {
    pub visitor_codes_to_send: Vec<String>,
    pub visitor_codes_to_keep: Vec<String>,
    pub unsent_trackable_data: Vec<Arc<TrackingStateCell>>,
    pub tracking_lines: Vec<String>,
}

impl TrackingData {
    pub fn new() -> Self {
        Self {
            visitor_codes_to_send: Vec::new(),
            visitor_codes_to_keep: Vec::new(),
            unsent_trackable_data: Vec::new(),
            tracking_lines: Vec::new(),
        }
    }

    pub fn reserve_approximately(&mut self, request_size_limit: usize, visitors_count: usize) {
        const VISITOR_SIZE_APPROX: usize = 256;
        const VISITOR_DATA_COUNT_APPROX: usize = 4;
        let visitor_max_count_approx = request_size_limit / VISITOR_SIZE_APPROX;
        let visitor_count_approx = visitors_count.min(visitor_max_count_approx);
        self.visitor_codes_to_send.reserve(visitor_count_approx);
        let data_count_approx = visitor_count_approx * VISITOR_DATA_COUNT_APPROX;
        self.unsent_trackable_data.reserve(data_count_approx);
        self.tracking_lines.reserve(data_count_approx);
    }
}
