use chrono::{DateTime, Utc}; use collab_entity::{CollabType, EncodedCollab}; use database_entity::dto::{AFRole, AFWebUser, AFWorkspaceInvitationStatus}; use serde::{Deserialize, Serialize}; use serde_repr::{Deserialize_repr, Serialize_repr}; use std::{collections::HashMap, ops::Deref}; use uuid::Uuid; #[derive(Deserialize, Serialize)] pub struct WorkspaceMembers(pub Vec); #[derive(Deserialize, Serialize)] pub struct WorkspaceMember(pub String); impl Deref for WorkspaceMember { type Target = String; fn deref(&self) -> &Self::Target { &self.0 } } impl From> for WorkspaceMembers { fn from(value: Vec) -> Self { Self(value.into_iter().map(WorkspaceMember).collect()) } } #[derive(Deserialize, Serialize)] pub struct CreateWorkspaceMembers(pub Vec); impl From> for CreateWorkspaceMembers { fn from(value: Vec) -> Self { Self(value) } } // Deprecated #[derive(Deserialize, Serialize)] pub struct CreateWorkspaceMember { pub email: String, pub role: AFRole, } #[derive(Debug, Deserialize, Serialize)] pub struct WorkspaceMemberInvitation { pub email: String, pub role: AFRole, } #[derive(Deserialize)] pub struct WorkspaceInviteQuery { pub status: Option, } #[derive(Deserialize, Serialize)] pub struct WorkspaceMemberChangeset { pub email: String, pub role: Option, pub name: Option, } impl WorkspaceMemberChangeset { pub fn new(email: String) -> Self { Self { email, role: None, name: None, } } pub fn with_role>(mut self, role: T) -> Self { self.role = Some(role.into()); self } pub fn with_name(mut self, name: String) -> Self { self.name = Some(name); self } } #[derive(Deserialize, Serialize)] pub struct WorkspaceSpaceUsage { pub consumed_capacity: u64, } #[derive(Serialize, Deserialize)] pub struct RepeatedBlobMetaData(pub Vec); #[derive(Serialize, Deserialize)] pub struct BlobMetadata { pub workspace_id: Uuid, pub file_id: String, pub file_type: String, pub file_size: i64, pub modified_at: DateTime, } #[derive(Serialize, Deserialize)] pub struct CreateWorkspaceParam { pub workspace_name: Option, } #[derive(Serialize, Deserialize, Default)] pub struct PatchWorkspaceParam { pub workspace_id: Uuid, pub workspace_name: Option, pub workspace_icon: Option, } #[derive(Serialize, Deserialize)] pub struct CollabTypeParam { pub collab_type: CollabType, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct CollabResponse { #[serde(flatten)] pub encode_collab: EncodedCollab, /// Object ID is marked with `serde(default)` to handle cases where `object_id` is missing in the data. /// This scenario can occur if the server data does not include `object_id` due to version downgrades (pre-0325 versions). /// The default ensures graceful handling of missing `object_id` during deserialization, preventing errors in client applications /// that expect this field to exist. /// /// We can remove this 'serde(default)' after the 0325 version is stable. #[serde(default)] pub object_id: String, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PageCollabData { pub encoded_collab: Vec, pub row_data: HashMap>, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PageCollab { pub view: FolderView, pub data: PageCollabData, pub owner: Option, pub last_editor: Option, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PublishedDuplicate { pub published_view_id: String, pub dest_view_id: String, } #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct FolderView { pub view_id: String, pub name: String, pub icon: Option, pub is_space: bool, pub is_private: bool, pub is_published: bool, pub layout: ViewLayout, pub created_at: DateTime, pub last_edited_time: DateTime, /// contains fields like `is_space`, and font information pub extra: Option, pub children: Vec, } #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct FolderViewMinimal { pub view_id: String, pub name: String, pub icon: Option, pub layout: ViewLayout, } #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct SectionItems { pub views: Vec, } #[derive(Eq, PartialEq, Debug, Hash, Clone, Serialize_repr, Deserialize_repr)] #[repr(u8)] pub enum IconType { Emoji = 0, Url = 1, Icon = 2, } #[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] pub struct ViewIcon { pub ty: IconType, pub value: String, } #[derive(Eq, PartialEq, Debug, Hash, Clone, Serialize_repr, Deserialize_repr)] #[repr(u8)] pub enum ViewLayout { Document = 0, Grid = 1, Board = 2, Calendar = 3, Chat = 4, } impl Default for ViewLayout { fn default() -> Self { Self::Document } } #[derive(Default, Debug, Deserialize, Serialize)] pub struct QueryWorkspaceParam { pub include_member_count: Option, } #[derive(Default, Debug, Deserialize, Serialize)] pub struct QueryWorkspaceFolder { pub depth: Option, pub root_view_id: Option, } #[derive(Default, Debug, Clone, Serialize, Deserialize)] pub struct PublishedView { pub view_id: String, pub name: String, pub icon: Option, pub layout: ViewLayout, pub is_published: bool, /// contains fields like `is_space`, and font information pub extra: Option, pub children: Vec, }