1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! # Schema Traits
//!
//! Defines the contracts (traits) that the macro implements.
//!
//! ## Architecture: Why Traits?
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────────────────┐
//! │ TRAIT-BASED ABSTRACTION │
//! ├─────────────────────────────────────────────────────────────────────────────┤
//! │ │
//! │ PROBLEM: │
//! │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
//! │ │ PracticeSchema │ │ RestaurantSchema│ │ HotelSchema │ │
//! │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
//! │ ↓ ↓ ↓ │
//! │ How does the compiler treat all these types uniformly? │
//! │ │
//! │ SOLUTION: Common contract (Trait) │
//! │ ┌─────────────────────────────────────────────────────────────┐ │
//! │ │ trait Validate │ │
//! │ │ fn validate(&self) -> Result<(), ValidationError> │ │
//! │ └─────────────────────────────────────────────────────────────┘ │
//! │ ↑ ↑ ↑ │
//! │ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
//! │ │ PracticeSchema │ │ RestaurantSchema│ │ HotelSchema │ │
//! │ │ impl Validate │ │ impl Validate │ │ impl Validate │ │
//! │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
//! │ │
//! │ Compiler can now work with `dyn Validate` or generics │
//! │ │
//! └─────────────────────────────────────────────────────────────────────────────┘
//! ```
use crateValidationError;
// ============================================================================
// SCHEMA METADATA
// ============================================================================
/// Trait for schema metadata.
///
/// Automatically implemented by the `#[derive(GermanicSchema)]` macro.
///
/// ## Usage
///
/// ```rust,ignore
/// use germanic::schema::SchemaMetadata;
///
/// let practice = PracticeSchema { /* ... */ };
/// println!("Schema-ID: {}", practice.schema_id()); // "de.gesundheit.praxis.v1"
/// ```
///
/// ## Architectural Significance
///
/// The schema ID is written to the .grm header and enables:
/// - AI systems can identify the schema
/// - Versioning for backward compatibility
/// - Registry lookup for schema definitions
// ============================================================================
// VALIDATION
// ============================================================================
/// Trait for schema validation.
///
/// Checks if all required fields (`#[germanic(required)]`) are filled.
///
/// ## Example
///
/// ```rust,ignore
/// use germanic::schema::Validate;
///
/// let practice = PracticeSchema {
/// name: "".to_string(), // EMPTY! → Error
/// bezeichnung: "Heilpraktiker".to_string(),
/// // ...
/// };
///
/// match practice.validate() {
/// Ok(()) => println!("All good"),
/// Err(e) => eprintln!("Validation failed: {}", e),
/// }
/// ```
///
/// ## Architectural Significance
///
/// Validation happens **before** FlatBuffer serialization.
/// This guarantees:
/// - Early failure (fail fast)
/// - No corrupt .grm files
/// - Meaningful error messages for the user
// ============================================================================
// SERIALIZATION (Placeholder for later)
// ============================================================================
/// Trait for FlatBuffer serialization.
///
/// **Not yet implemented** – coming in Phase 3 of macro development.
///
/// ## Planned Signature
///
/// ```rust,ignore
/// pub trait GermanicSerialize {
/// /// Serializes the schema into FlatBuffer bytes.
/// fn serialize(&self, builder: &mut FlatBufferBuilder) -> WIPOffset<UnionWIPOffset>;
/// }
/// ```
// ============================================================================
// COMPOSITION TRAIT
// ============================================================================
/// Marker trait for complete GERMANIC schemas.
///
/// A type implements `GermanicSchemaComplete` if it implements all
/// necessary traits.
///
/// ## Automatic Implementation
///
/// ```rust,ignore
/// // Automatically for any type that implements all traits:
/// impl<T> GermanicSchemaComplete for T
/// where
/// T: SchemaMetadata + Validate + GermanicSerialize
/// {}
/// ```
// Blanket implementation: Any type that has all traits is automatically complete