use std::fmt::Display;

use serde::{Deserialize, Serialize};

use super::class_type::ClassTypeName;

#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ClassName(pub String);

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Class {
    pub name: ClassName,
    pub class_type: ClassTypeName,
}

impl From<Class> for ClassName {
    fn from(value: Class) -> Self {
        value.name
    }
}

impl From<&str> for ClassName {
    fn from(value: &str) -> Self {
        ClassName(value.to_owned())
    }
}

impl Display for ClassName {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl Class {
    pub fn new(class: &str, class_type: ClassTypeName) -> Self {
        Self {
            name: ClassName(class.to_owned()),
            class_type,
        }
    }
}
