pub mod digest;
pub mod hikvision;
pub mod types;
use async_trait::async_trait;
use crate::error::{AppError, AppResult};
use crate::models::Camera;
use types::{
DeviceInfo, NtpConfig, OnvifSettings, OnvifUserType, OsdConfig, TimeConfig, VideoConfig,
};
#[async_trait]
pub trait CameraConfigProvider: Send + Sync {
async fn get_device_info(&self) -> AppResult<DeviceInfo>;
async fn list_video_configs(&self) -> AppResult<Vec<VideoConfig>>;
async fn get_video_config(&self, channel: u32) -> AppResult<VideoConfig>;
async fn put_video_config(&self, channel: u32, cfg: &VideoConfig) -> AppResult<()>;
async fn get_time_config(&self) -> AppResult<TimeConfig>;
async fn put_time_config(&self, cfg: &TimeConfig) -> AppResult<()>;
async fn get_ntp_config(&self) -> AppResult<NtpConfig>;
async fn put_ntp_config(&self, cfg: &NtpConfig) -> AppResult<()>;
async fn sync_time_now(&self) -> AppResult<TimeConfig>;
async fn get_onvif_settings(&self) -> AppResult<OnvifSettings>;
async fn put_onvif_settings(&self, cfg: &OnvifSettings) -> AppResult<()>;
async fn ensure_onvif_user(
&self,
username: &str,
password: &str,
user_type: OnvifUserType,
) -> AppResult<()>;
async fn get_osd_config(&self) -> AppResult<OsdConfig>;
async fn put_osd_config(&self, cfg: &OsdConfig) -> AppResult<()>;
async fn reboot(&self) -> AppResult<()>;
}
pub fn for_camera(
cam: &Camera,
http: &reqwest::Client,
timeout_ms: u64,
) -> AppResult<Box<dyn CameraConfigProvider>> {
match cam.vendor.as_str() {
"hikvision" => Ok(Box::new(hikvision::HikVisionIsapiClient::for_camera(
cam, http, timeout_ms,
)?)),
_ => Err(AppError::BadRequest(
"camera config only supported for hikvision; ONVIF-generic is a future impl".into(),
)),
}
}