use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Word {
    pub text: String,
    pub frequency: f64,
    pub length: usize,
}

impl Word {
    pub fn new(text: String, frequency: f64) -> Self {
        let length = text.len();
        Self {
            text,
            frequency,
            length,
        }
    }

    pub fn char_at(&self, pos: usize) -> u8 {
        self.text.as_bytes()[pos]
    }
}
