gbserver/gb-core/src/models.rs

194 lines
4.3 KiB
Rust
Raw Normal View History

2024-12-23 17:36:12 -03:00
//! Core domain models for the general-bots system
//! File: gb-core/src/models.rs
2024-12-22 20:56:52 -03:00
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
2024-12-23 17:36:12 -03:00
use serde_json::Value as JsonValue;
use std::str::FromStr;
2024-12-22 20:56:52 -03:00
use uuid::Uuid;
2024-12-23 17:36:12 -03:00
#[derive(Debug)]
pub struct CoreError(pub String);
2024-12-22 20:56:52 -03:00
2024-12-23 17:36:12 -03:00
#[derive(Debug, Serialize, Deserialize)]
2024-12-22 20:56:52 -03:00
pub struct Instance {
pub id: Uuid,
pub customer_id: Uuid,
pub name: String,
2024-12-23 17:36:12 -03:00
pub status: String,
2024-12-22 20:56:52 -03:00
pub shard_id: i32,
2024-12-23 17:36:12 -03:00
pub region: String,
pub config: JsonValue,
2024-12-22 20:56:52 -03:00
pub created_at: DateTime<Utc>,
}
2024-12-23 17:36:12 -03:00
#[derive(Debug, Serialize, Deserialize)]
2024-12-22 20:56:52 -03:00
pub struct Room {
pub id: Uuid,
pub instance_id: Uuid,
pub name: String,
2024-12-23 17:36:12 -03:00
pub kind: String,
pub status: String,
pub config: JsonValue,
2024-12-22 20:56:52 -03:00
pub created_at: DateTime<Utc>,
2024-12-23 17:36:12 -03:00
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
pub id: Uuid,
pub customer_id: Uuid,
pub instance_id: Uuid,
pub conversation_id: Uuid,
pub sender_id: Uuid,
pub kind: String,
pub content: String,
pub metadata: JsonValue,
pub created_at: DateTime<Utc>,
pub shard_key: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MessageFilter {
pub conversation_id: Option<Uuid>,
pub sender_id: Option<Uuid>,
pub from_date: Option<DateTime<Utc>>,
pub to_date: Option<DateTime<Utc>>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SearchQuery {
pub query: String,
pub conversation_id: Option<Uuid>,
pub from_date: Option<DateTime<Utc>>,
pub to_date: Option<DateTime<Utc>>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FileUpload {
pub content: Vec<u8>,
pub filename: String,
pub content_type: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct FileContent {
pub content: Vec<u8>,
pub content_type: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Status {
pub code: String,
pub timestamp: DateTime<Utc>,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum UserStatus {
Active,
Inactive,
Suspended,
}
impl FromStr for UserStatus {
type Err = CoreError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"active" => Ok(UserStatus::Active),
"inactive" => Ok(UserStatus::Inactive),
"suspended" => Ok(UserStatus::Suspended),
_ => Ok(UserStatus::Inactive)
}
}
2024-12-22 20:56:52 -03:00
}
#[derive(Debug, Clone, Serialize, Deserialize)]
2024-12-23 00:20:59 -03:00
pub struct Track {
2024-12-22 20:56:52 -03:00
pub id: Uuid,
2024-12-23 00:20:59 -03:00
pub room_id: Uuid,
pub user_id: Uuid,
pub media_type: String,
2024-12-22 20:56:52 -03:00
pub created_at: DateTime<Utc>,
2024-12-23 00:20:59 -03:00
pub updated_at: DateTime<Utc>,
2024-12-22 20:56:52 -03:00
}
2024-12-23 17:36:12 -03:00
#[derive(Debug, Serialize, Deserialize)]
2024-12-23 00:20:59 -03:00
pub struct User {
2024-12-22 20:56:52 -03:00
pub id: Uuid,
2024-12-23 17:36:12 -03:00
pub customer_id: Uuid,
2024-12-23 00:20:59 -03:00
pub instance_id: Uuid,
pub name: String,
2024-12-23 17:36:12 -03:00
pub email: String,
pub password_hash: String,
pub status: UserStatus,
pub metadata: JsonValue,
2024-12-23 00:20:59 -03:00
pub created_at: DateTime<Utc>,
2024-12-22 20:56:52 -03:00
}
#[derive(Debug, Clone, Serialize, Deserialize)]
2024-12-23 00:20:59 -03:00
pub struct Customer {
2024-12-22 20:56:52 -03:00
pub id: Uuid,
pub name: String,
2024-12-23 17:36:12 -03:00
pub max_instances: u32,
2024-12-22 20:56:52 -03:00
pub email: String,
pub created_at: DateTime<Utc>,
2024-12-23 00:20:59 -03:00
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomConfig {
pub instance_id: Uuid,
pub name: String,
pub max_participants: u32,
2024-12-22 20:56:52 -03:00
}
2024-12-23 00:20:59 -03:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Connection {
pub id: Uuid,
pub room_id: Uuid,
pub user_id: Uuid,
pub connected_at: DateTime<Utc>,
2024-12-22 20:56:52 -03:00
}
2024-12-23 00:20:59 -03:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrackInfo {
pub room_id: Uuid,
pub user_id: Uuid,
pub media_type: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Subscription {
pub id: Uuid,
pub track_id: Uuid,
pub subscriber_id: Uuid,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Participant {
pub user_id: Uuid,
pub room_id: Uuid,
pub joined_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoomStats {
pub participant_count: u32,
pub track_count: u32,
pub duration: i64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MessageId(pub Uuid);
2024-12-23 17:36:12 -03:00
#[derive(Debug, Serialize, Deserialize)]
2024-12-23 00:20:59 -03:00
pub struct FileInfo {
pub id: Uuid,
pub filename: String,
pub content_type: String,
2024-12-23 17:36:12 -03:00
pub size: usize,
pub url: String,
2024-12-23 00:20:59 -03:00
pub created_at: DateTime<Utc>,
}