use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Database {
pub id: String,
pub name: String,
pub description: String,
pub created_at: chrono::DateTime<chrono::Utc>,
pub updated_at: chrono::DateTime<chrono::Utc>,
pub config: DatabaseConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseConfig {
pub encryption_algorithm: String,
pub key_rotation_interval_days: i32,
pub enable_audit_logging: bool,
pub custom_settings: HashMap<String, String>,
}
impl Default for DatabaseConfig {
fn default() -> Self {
Self {
encryption_algorithm: "aes-256-gcm".to_string(),
key_rotation_interval_days: 30,
enable_audit_logging: true,
custom_settings: HashMap::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateDatabaseRequest {
pub name: String,
pub description: String,
pub config: Option<DatabaseConfig>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatabaseResponse {
pub database: Database,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetDatabaseRequest {
pub database_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListDatabasesRequest {
pub page_size: i32,
pub page_token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListDatabasesResponse {
pub databases: Vec<Database>,
pub next_page_token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteDatabaseRequest {
pub database_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EncryptRequest {
pub database_id: String,
pub plaintext: Vec<u8>,
pub key_id: Option<String>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EncryptResponse {
pub ciphertext: Vec<u8>,
pub key_id: String,
pub encrypted_at: chrono::DateTime<chrono::Utc>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DecryptRequest {
pub database_id: String,
pub ciphertext: Vec<u8>,
pub key_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DecryptResponse {
pub plaintext: Vec<u8>,
pub decrypted_at: chrono::DateTime<chrono::Utc>,
pub metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthResponse {
pub status: i32,
pub version: String,
pub timestamp: chrono::DateTime<chrono::Utc>,
pub components: Vec<ComponentHealth>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComponentHealth {
pub name: String,
pub status: i32,
pub message: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricsResponse {
pub timestamp: chrono::DateTime<chrono::Utc>,
pub counters: HashMap<String, f64>,
pub gauges: HashMap<String, f64>,
pub histograms: HashMap<String, HistogramData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistogramData {
pub count: u64,
pub sum: f64,
pub buckets: Vec<f64>,
pub bucket_counts: Vec<u64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchEncryptRequest {
pub database_id: String,
pub items: Vec<BatchEncryptItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchEncryptItem {
pub data: Vec<u8>,
pub key_id: String,
pub encryption_algorithm: Option<String>,
pub context: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchEncryptResponse {
pub results: Vec<BatchEncryptResult>,
pub errors: Vec<BatchEncryptError>,
pub total_items: u32,
pub successful_items: u32,
pub failed_items: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchEncryptResult {
pub index: u32,
pub encrypted_data: String,
pub algorithm: String,
pub key_id: String,
pub timestamp: chrono::DateTime<chrono::Utc>,
pub success: bool,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchEncryptError {
pub index: u32,
pub error: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchDecryptRequest {
pub database_id: String,
pub items: Vec<BatchDecryptItem>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchDecryptItem {
pub encrypted_data: String,
pub key_id: String,
pub algorithm: Option<String>,
pub context: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchDecryptResponse {
pub results: Vec<BatchDecryptResult>,
pub errors: Vec<BatchDecryptError>,
pub total_items: u32,
pub successful_items: u32,
pub failed_items: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchDecryptResult {
pub index: u32,
pub data: Vec<u8>,
pub algorithm: String,
pub key_id: String,
pub timestamp: chrono::DateTime<chrono::Utc>,
pub success: bool,
pub error: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchDecryptError {
pub index: u32,
pub error: String,
}