/*
 * Cloud Hypervisor API
 *
 * Local HTTP based API for managing and inspecting a cloud-hypervisor virtual machine.
 *
 * The version of the OpenAPI document: 0.3.0
 *
 * Generated by: https://openapi-generator.tech
 */

use crate::models;
use serde::{Deserialize, Serialize};

/// TokenBucket : Defines a token bucket with a maximum capacity (_size_), an initial burst size (_one_time_burst_) and an interval for refilling purposes (_refill_time_). The refill-rate is derived from _size_ and _refill_time_, and it is the constant rate at which the tokens replenish. The refill process only starts happening after the initial burst budget is consumed. Consumption from the token bucket is unbounded in speed which allows for bursts bound in size by the amount of tokens available. Once the token bucket is empty, consumption speed is bound by the refill-rate.
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct TokenBucket {
    /// The total number of tokens this bucket can hold.
    #[serde(rename = "size")]
    pub size: i64,
    /// The initial size of a token bucket.
    #[serde(rename = "one_time_burst", skip_serializing_if = "Option::is_none")]
    pub one_time_burst: Option<i64>,
    /// The amount of milliseconds it takes for the bucket to refill.
    #[serde(rename = "refill_time")]
    pub refill_time: i64,
}

impl TokenBucket {
    /// Defines a token bucket with a maximum capacity (_size_), an initial burst size (_one_time_burst_) and an interval for refilling purposes (_refill_time_). The refill-rate is derived from _size_ and _refill_time_, and it is the constant rate at which the tokens replenish. The refill process only starts happening after the initial burst budget is consumed. Consumption from the token bucket is unbounded in speed which allows for bursts bound in size by the amount of tokens available. Once the token bucket is empty, consumption speed is bound by the refill-rate.
    pub fn new(size: i64, refill_time: i64) -> TokenBucket {
        TokenBucket {
            size,
            one_time_burst: None,
            refill_time,
        }
    }
}
