use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct ContentHashProjection {
pub id: Uuid,
pub hash: String,
pub size_bytes: i64,
pub storage_key: String,
pub storage_backend: StorageBackend,
pub reference_count: i32,
pub first_uploaded_at: DateTime<Utc>,
pub last_referenced_at: DateTime<Utc>,
pub fingerprint: Option<String>,
pub metadata: serde_json::Value,
pub projection_version: i64,
pub last_event_sequence: i64,
pub projection_updated_at: DateTime<Utc>,
}
impl ContentHashProjection {
pub fn new(
id: Uuid,
hash: String,
size_bytes: i64,
storage_key: String,
storage_backend: StorageBackend,
reference_count: i32,
first_uploaded_at: DateTime<Utc>,
last_referenced_at: DateTime<Utc>,
fingerprint: Option<String>,
metadata: serde_json::Value
) -> Self {
Self {
id,
hash,
size_bytes,
storage_key,
storage_backend,
reference_count,
first_uploaded_at,
last_referenced_at,
fingerprint,
metadata,
projection_version: 1,
last_event_sequence: 0,
projection_updated_at: Utc::now(),
}
}
pub fn id(&self) -> &Uuid {
&self.id
}
pub fn apply_event(&mut self, event_sequence: i64) {
self.projection_version += 1;
self.last_event_sequence = event_sequence;
self.projection_updated_at = Utc::now();
}
}
#[derive(Debug, Clone, Serialize, Deserialize, FromRow)]
pub struct ContentHashSummary {
pub id: Uuid,
}