use std::path::Path;
use serde::{Deserialize, Serialize};
use crate::{ModuleInfoFile, ObjectType, RawModuleLocation};
#[derive(Serialize, Deserialize, Clone, Debug, Default, specta::Type)]
#[serde(rename_all = "camelCase")]
pub struct Metadata {
module_object_id: String,
module_name: String,
module_version: String,
raw_file_path: String,
raw_identifier: String,
object_type: ObjectType,
raw_module_location: RawModuleLocation,
#[serde(skip)]
hidden: bool,
}
impl Metadata {
#[must_use]
pub fn new<P: AsRef<Path>>(
module_info: &ModuleInfoFile,
object_type: &ObjectType,
raw_identifier: &str,
raw_file_path: &P,
attach_metadata_to_raws: bool,
) -> Self {
Self {
module_name: module_info.get_name(),
module_version: module_info.get_version(),
raw_file_path: String::from(raw_file_path.as_ref().to_str().unwrap_or_default()),
raw_identifier: String::from(raw_identifier),
object_type: object_type.clone(),
raw_module_location: module_info.get_location(),
module_object_id: module_info.get_object_id(),
hidden: !attach_metadata_to_raws,
}
}
#[must_use]
pub const fn is_hidden(&self) -> bool {
self.hidden
}
pub fn get_raw_identifier(&self) -> &str {
&self.raw_identifier
}
pub fn get_module_name(&self) -> &str {
&self.module_name
}
pub fn get_module_numerical_version(&self) -> &str {
&self.module_version
}
pub fn get_module_version(&self) -> &str {
&self.module_version
}
pub fn get_raw_file_path(&self) -> &str {
&self.raw_file_path
}
pub const fn get_location(&self) -> &RawModuleLocation {
&self.raw_module_location
}
pub fn get_module_object_id(&self) -> &str {
&self.module_object_id
}
#[must_use]
pub const fn with_object_type(mut self, object_type: ObjectType) -> Self {
self.object_type = object_type;
self
}
#[must_use]
pub const fn with_raw_module_location(
mut self,
raw_module_location: RawModuleLocation,
) -> Self {
self.raw_module_location = raw_module_location;
self
}
#[must_use]
pub const fn with_hidden(mut self, hidden: bool) -> Self {
self.hidden = hidden;
self
}
#[must_use]
pub fn with_raw_identifier(mut self, raw_identifier: String) -> Self {
self.raw_identifier = raw_identifier;
self
}
#[must_use]
pub fn with_raw_file_path(mut self, raw_file_path: String) -> Self {
self.raw_file_path = raw_file_path;
self
}
#[must_use]
pub fn with_module_name(mut self, module_name: String) -> Self {
self.module_name = module_name;
self
}
#[must_use]
pub fn with_module_version(mut self, module_version: String) -> Self {
self.module_version = module_version;
self
}
#[must_use]
pub fn with_module_object_id(mut self, module_object_id: String) -> Self {
self.module_object_id = module_object_id;
self
}
}