//! Types that are required for the BFS queue implementation.

use std::cmp::Ordering;

#[derive(Clone, Debug)]
pub struct NodePriority {
    length: usize,
    trust_amount: u8,
}

impl NodePriority {
    pub fn new(length: usize, trust_amount: u8) -> Self {
        NodePriority {
            length,
            trust_amount,
        }
    }
}

use std::fmt;

impl fmt::Display for NodePriority {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "[ length: {}, trust: {} ]",
            self.length, self.trust_amount
        )
    }
}

impl Ord for NodePriority {
    fn cmp(&self, other: &Self) -> Ordering {
        match self.length.cmp(&other.length) {
            Ordering::Equal => self.trust_amount.cmp(&other.trust_amount),
            Ordering::Less => Ordering::Greater,
            Ordering::Greater => Ordering::Less,
        }
    }
}

impl PartialOrd for NodePriority {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for NodePriority {
    fn eq(&self, other: &Self) -> bool {
        self.length == other.length && self.trust_amount == other.trust_amount
    }
}

impl Eq for NodePriority {}
