//! Domain types shared by the recording pipeline, the SQLite store and the //! Tauri command layer. use std::path::PathBuf; use chrono::{DateTime, Local}; use serde::{Deserialize, Serialize}; /// Primary key of a `calls` row (SQLite `rowid`). pub type CallId = i64; /// Lifecycle state of a recorded call. /// /// Serializes (and is persisted) as its lowercase snake_case name, e.g. /// `CallStatus::AwaitingDecision` -> `"awaiting_decision"`. #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] #[serde(rename_all = "snake_case")] pub enum CallStatus { Recording, AwaitingDecision, Processing, Done, Failed, } /// A single recorded call and everything tracked about its lifecycle. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub struct Call { pub id: CallId, pub app: String, pub started_at: DateTime, pub ended_at: Option>, pub status: CallStatus, pub interrupted: bool, pub error: Option, pub mic_path: PathBuf, pub out_path: PathBuf, pub transcribed_at: Option>, pub audio_deleted: bool, /// The name the user gave the call, if any. pub title: Option, /// The id the CRM gave the transcript at its last upload. pub crm_transcript_id: Option, /// The backend ([`crate::backend`]'s base URL) `crm_transcript_id` was /// uploaded to; `None` if never uploaded. A build whose own backend /// differs (e.g. release reading a row a test build uploaded) does not /// count this as uploaded — see `call_view::uploaded_here`. pub crm_base_url: Option, /// When the transcript was last uploaded. pub uploaded_at: Option>, } /// A single transcribed word with its timing and speaker attribution. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub struct Word { pub text: String, pub start: f64, pub end: f64, pub speaker: Option, } /// Who is speaking in a segment: the local user, or one of the remote /// participants detected via diarization. #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] pub enum Speaker { Me, Remote(u32), } impl Speaker { /// Stable identifier used as a storage/lookup key, e.g. for /// `Store::set_speaker_name` / `Store::speaker_names`. pub fn key(&self) -> String { match self { Speaker::Me => "me".to_string(), Speaker::Remote(n) => format!("remote:{n}"), } } /// Default German display label before the user renames a speaker. pub fn default_label(&self) -> String { match self { Speaker::Me => "Ich".to_string(), Speaker::Remote(n) => format!("Sprecher {n}"), } } /// Parses a key produced by [`Speaker::key`] back into a `Speaker`. pub fn from_key(key: &str) -> Option { if key == "me" { Some(Speaker::Me) } else { key.strip_prefix("remote:") .and_then(|n| n.parse::().ok()) .map(Speaker::Remote) } } } /// A merged, diarized stretch of transcript attributed to one speaker. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] pub struct Segment { pub speaker: Speaker, pub start: f64, pub end: f64, pub text: String, }