@@ -72,6 +72,80 @@ macro_rules! wp_mobile_item_state {
7272 } ;
7373}
7474
75+ /// Macro to create UniFFI-compatible metadata collection item types.
76+ ///
77+ /// This macro generates both the state enum and the collection item struct for
78+ /// metadata-driven collections. The generated types are suitable for use across
79+ /// language boundaries via UniFFI.
80+ ///
81+ /// # Parameters
82+ /// - `$item_name`: Name for the collection item struct (e.g., `PostMetadataCollectionItem`)
83+ /// - `$state_name`: Name for the state enum (e.g., `PostItemState`)
84+ /// - `$full_entity_type`: The FullEntity wrapper type (e.g., `FullEntityAnyPostWithEditContext`)
85+ ///
86+ /// # Generated Types
87+ ///
88+ /// ## State Enum (`$state_name`)
89+ /// - `Missing`: No cached data, needs fetch
90+ /// - `Fetching`: Fetch in progress, no cached data
91+ /// - `FetchingWithData { data }`: Fetch in progress, showing cached data
92+ /// - `Cached { data }`: Fresh cached data
93+ /// - `Stale { data }`: Outdated cached data
94+ /// - `Failed { error }`: Fetch failed, no cached data
95+ /// - `FailedWithData { error, data }`: Fetch failed, showing cached data
96+ ///
97+ /// ## Collection Item Struct (`$item_name`)
98+ /// - `id: i64`: The entity ID
99+ /// - `parent: Option<i64>`: Parent entity ID (from list metadata, for hierarchical types)
100+ /// - `menu_order: Option<i64>`: Menu order (from list metadata, for hierarchical types)
101+ /// - `state: $state_name`: The combined state and data
102+ ///
103+ /// # Usage
104+ /// ```ignore
105+ /// wp_mobile_metadata_item!(
106+ /// PostMetadataCollectionItem,
107+ /// PostItemState,
108+ /// FullEntityAnyPostWithEditContext
109+ /// );
110+ /// ```
111+ #[ macro_export]
112+ macro_rules! wp_mobile_metadata_item {
113+ ( $item_name: ident, $state_name: ident, $full_entity_type: ty) => {
114+ // Generate the state enum using the existing macro
115+ $crate:: wp_mobile_item_state!( $state_name, $full_entity_type) ;
116+
117+ /// Item in a metadata collection with type-safe state representation.
118+ ///
119+ /// The `state` enum encodes both the sync status and data availability,
120+ /// making it impossible to have inconsistent combinations.
121+ ///
122+ /// The `parent` and `menu_order` fields come from the list metadata store,
123+ /// making them available immediately without waiting for full entity data
124+ /// to be fetched. This enables building hierarchical views (like page trees)
125+ /// as soon as the list structure is known.
126+ #[ derive( uniffi:: Record ) ]
127+ pub struct $item_name {
128+ /// The entity ID
129+ pub id: i64 ,
130+
131+ /// Parent entity ID (from list metadata, for hierarchical post types like pages)
132+ ///
133+ /// This value comes from the list metadata, so it's available immediately
134+ /// without waiting for the full post data to be fetched.
135+ pub parent: Option <i64 >,
136+
137+ /// Menu order (from list metadata, for hierarchical post types)
138+ ///
139+ /// This value comes from the list metadata, so it's available immediately
140+ /// without waiting for the full post data to be fetched.
141+ pub menu_order: Option <i64 >,
142+
143+ /// Combined state and data - see the state enum for variants
144+ pub state: $state_name,
145+ }
146+ } ;
147+ }
148+
75149/// Macro to create UniFFI-compatible post collection wrappers
76150///
77151/// This macro generates a wrapper type for `PostCollection<T>` that can be used
0 commit comments