1use serde::{Deserialize, Serialize};
4
5use super::AppEvent;
6
7#[derive(Debug, Clone, Serialize, Deserialize)]
11#[cfg_attr(feature = "ts-bindings", derive(ts_rs::TS), ts(export))]
12#[serde(rename_all = "camelCase")]
13pub struct ModelSummary {
14 #[cfg_attr(feature = "ts-bindings", ts(type = "number"))]
16 pub id: i64,
17 pub name: String,
19 pub file_path: String,
21 #[cfg_attr(feature = "ts-bindings", ts(optional))]
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub architecture: Option<String>,
25 #[cfg_attr(feature = "ts-bindings", ts(optional))]
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub quantization: Option<String>,
29}
30
31impl ModelSummary {
32 pub fn new(
34 id: i64,
35 name: impl Into<String>,
36 file_path: impl Into<String>,
37 architecture: Option<String>,
38 quantization: Option<String>,
39 ) -> Self {
40 Self {
41 id,
42 name: name.into(),
43 file_path: file_path.into(),
44 architecture,
45 quantization,
46 }
47 }
48}
49
50impl From<&crate::domain::Model> for ModelSummary {
56 fn from(model: &crate::domain::Model) -> Self {
57 Self {
58 id: model.id,
59 name: model.name.clone(),
60 file_path: model.file_path.to_string_lossy().into_owned(),
61 architecture: model.architecture.clone(),
62 quantization: model.quantization.clone(),
63 }
64 }
65}
66
67impl AppEvent {
68 pub const fn model_added(model: ModelSummary) -> Self {
70 Self::ModelAdded { model }
71 }
72
73 pub const fn model_removed(model_id: i64) -> Self {
75 Self::ModelRemoved { model_id }
76 }
77
78 pub const fn model_updated(model: ModelSummary) -> Self {
80 Self::ModelUpdated { model }
81 }
82}