use wot_network::Binding;

use crate::types::certification::Certification;

#[derive(Debug, Clone)]
pub(crate) struct TargetNode {
    /// The certificate that this node represents.
    pub binding: Binding,

    /// The certifications that point towards the [`Binding`] of this node.
    pub certifications: Vec<Certification>,

    /// `allowed_amount` is a static value that indicates the maximum amount of trust that can be
    /// directed through this node.
    pub allowed_amount: u8,

    /// `used_amount` is a runtime variable that's used to track how much trust amount has already
    /// been directed through this node.
    ///
    /// This variable persists and is updated between steps.
    pub used_amount: u8,
}

impl TargetNode {
    /// Constructs a new [`TargetNode`] with the specified binding and associated certifications.
    pub fn new(binding: Binding, certifications: Vec<Certification>) -> Self {
        TargetNode {
            binding,
            certifications,
            allowed_amount: 120,
            used_amount: 0,
        }
    }

    /// Returns the remaining trust capacity that can be directed through this node.
    pub fn available_amount(&self) -> u8 {
        self.allowed_amount.saturating_sub(self.used_amount)
    }
}
