use isolang::Language;
pub use oca_ast::ast::AttributeType;
use oca_ast::ast::{NestedAttrType, NestedValue};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
pub type OverlayName = String;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Attribute {
pub name: String,
#[serde(rename = "type")]
pub attribute_type: Option<NestedAttrType>,
pub properties: Option<HashMap<OverlayName, NestedValue>>,
}
impl Default for Attribute {
fn default() -> Self {
Self::new("".to_string())
}
}
impl Attribute {
pub fn new(name: String) -> Attribute {
Attribute {
name,
attribute_type: None,
properties: None,
}
}
pub fn set_attribute_type(&mut self, attribute_type: NestedAttrType) {
self.attribute_type = Some(attribute_type);
}
pub fn merge(&mut self, other: &Attribute) {
if self.name != other.name {
panic!("Cannot merge attributes with different names");
} else if other.attribute_type.is_some() {
self.attribute_type.clone_from(&other.attribute_type);
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Entry {
pub id: String,
pub translations: HashMap<Language, String>,
}
impl Entry {
pub fn new(id: String, translations: HashMap<Language, String>) -> Entry {
Entry { id, translations }
}
}