use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Default, Serialize, Deserialize)]
pub struct State {
pub version: u32,
pub devices: BTreeMap<String, Device>,
pub enrol_codes: BTreeMap<String, EnrolCode>,
pub nonces: BTreeMap<String, BTreeMap<String, u64>>,
pub jobs: BTreeMap<String, Job>,
pub idempotency: BTreeMap<String, IdemRecord>,
pub webhook_seen: BTreeMap<String, u64>,
pub webhook_inbox: Vec<InboxItem>,
#[serde(default)]
pub tasks: BTreeMap<String, Task>,
#[serde(default)]
pub task_seq: u64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TaskStatus {
Queued,
Leased,
Done,
Failed,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Task {
pub id: String,
pub seq: u64,
pub target: Option<String>,
pub method: String,
pub params: Value,
pub lease_ttl: u64,
pub status: TaskStatus,
pub owner: Option<String>,
pub epoch: u64,
pub expires: u64,
pub acked: bool,
pub created_at: u64,
pub outcome: Option<Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Device {
pub public_key: String,
pub label: Option<String>,
pub scopes: Vec<String>,
pub enrolled_at: u64,
pub revoked: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EnrolCode {
pub scopes: Vec<String>,
pub expires_at: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Job {
pub revision: u64,
pub fields: serde_json::Map<String, Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IdemRecord {
pub request_hash: String,
pub status: u16,
pub body: Value,
pub at: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InboxItem {
pub id: String,
pub provider: String,
pub received_at: u64,
pub body_b64: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Upload {
pub id: String,
pub device_id: String,
pub size: u64,
pub chunk_bytes: u64,
pub chunk_count: u64,
pub key_hex: String,
pub created_at: u64,
pub expires_at: u64,
pub received: BTreeMap<u64, String>,
pub complete: Option<UploadDone>,
#[serde(skip)]
pub finalizing: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UploadDone {
pub digest: String,
pub completed_at: u64,
}