Skip to main content

heldar_kernel/models/
scheduling.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4use sqlx::types::Json;
5use sqlx::FromRow;
6
7/// A per-camera schedule that captures a live JPEG every `interval_seconds`.
8#[derive(Debug, Clone, Serialize, FromRow)]
9pub struct SnapshotSchedule {
10    pub id: String,
11    pub camera_id: String,
12    pub interval_seconds: i64,
13    pub enabled: bool,
14    pub last_fired_at: Option<DateTime<Utc>>,
15    pub created_at: DateTime<Utc>,
16    pub updated_at: DateTime<Utc>,
17}
18
19#[derive(Debug, Deserialize)]
20pub struct SnapshotScheduleCreate {
21    pub interval_seconds: Option<i64>,
22    pub enabled: Option<bool>,
23}
24
25#[derive(Debug, Deserialize, Default)]
26pub struct SnapshotScheduleUpdate {
27    pub interval_seconds: Option<i64>,
28    pub enabled: Option<bool>,
29}
30
31/// A captured snapshot frame on disk (one file under snapshots_dir/{camera_id}/).
32#[derive(Debug, Clone, Serialize, FromRow)]
33pub struct PersistedSnapshot {
34    pub id: String,
35    pub camera_id: String,
36    pub schedule_id: Option<String>,
37    pub path: String,
38    pub taken_at: DateTime<Utc>,
39    pub size_bytes: i64,
40    pub created_at: DateTime<Utc>,
41}
42
43/// A recurring per-camera recording window, applied when the camera's `record_mode` is `scheduled`
44/// or `scheduled_event`. `days` is a JSON array of weekday ints (0=Mon..6=Sun); `time_start` /
45/// `time_end` are "HH:MM" 24h in the SERVER's LOCAL timezone (chrono::Local). When `time_start` >
46/// `time_end` the window wraps past midnight (its early-morning portion is attributed to the day it
47/// started on).
48#[derive(Debug, Clone, Serialize, FromRow)]
49pub struct RecordSchedule {
50    pub id: String,
51    pub camera_id: String,
52    pub days: Json<Value>,
53    pub time_start: String,
54    pub time_end: String,
55    pub enabled: bool,
56    pub created_at: DateTime<Utc>,
57    pub updated_at: DateTime<Utc>,
58}
59
60#[derive(Debug, Deserialize)]
61pub struct RecordScheduleCreate {
62    /// JSON array of weekday ints (0=Mon..6=Sun).
63    pub days: Value,
64    /// "HH:MM" 24h, server local time.
65    pub time_start: String,
66    /// "HH:MM" 24h, server local time (start > end means an overnight window).
67    pub time_end: String,
68    pub enabled: Option<bool>,
69}
70
71#[derive(Debug, Deserialize, Default)]
72pub struct RecordScheduleUpdate {
73    pub days: Option<Value>,
74    pub time_start: Option<String>,
75    pub time_end: Option<String>,
76    pub enabled: Option<bool>,
77}