use crate::types::Type;
use std::fmt::{Display, Formatter, Write};
use std::sync::Arc;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Range {
    pub of: Arc<Type>,
}

impl Range {
    pub fn new(of: Type) -> Range {
        Range { of: Arc::new(of) }
    }

    pub fn fmt_indented(
        &self,
        f: &mut impl Write,
        prefix: &str,
        indentation: usize,
        max_fields: usize,
    ) -> std::fmt::Result {
        write!(f, "{prefix}(")?;
        self.of.fmt_indented(f, indentation, max_fields)?;
        write!(f, ")")
    }
}

impl Display for Range {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        self.fmt_indented(f, "range", 0, usize::MAX)
    }
}
