tx2_pack/
metadata.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct SnapshotMetadata {
6    pub id: String,
7    pub name: Option<String>,
8    pub description: Option<String>,
9    pub created_at: i64,
10    pub world_time: f64,
11    pub schema_version: u32,
12    pub custom_fields: HashMap<String, String>,
13    pub tags: Vec<String>,
14}
15
16impl SnapshotMetadata {
17    pub fn new(id: String) -> Self {
18        Self {
19            id,
20            name: None,
21            description: None,
22            created_at: chrono::Utc::now().timestamp(),
23            world_time: 0.0,
24            schema_version: 1,
25            custom_fields: HashMap::new(),
26            tags: Vec::new(),
27        }
28    }
29
30    pub fn with_name(mut self, name: String) -> Self {
31        self.name = Some(name);
32        self
33    }
34
35    pub fn with_description(mut self, description: String) -> Self {
36        self.description = Some(description);
37        self
38    }
39
40    pub fn with_tag(mut self, tag: String) -> Self {
41        self.tags.push(tag);
42        self
43    }
44
45    pub fn with_custom_field(mut self, key: String, value: String) -> Self {
46        self.custom_fields.insert(key, value);
47        self
48    }
49}