koprogo_api/application/ports/
iot_repository.rs1use crate::application::dto::{ConsumptionStatsDto, DailyAggregateDto, MonthlyAggregateDto};
2use crate::domain::entities::{DeviceType, IoTReading, LinkyDevice, MetricType};
3use async_trait::async_trait;
4use chrono::{DateTime, Utc};
5use uuid::Uuid;
6
7#[async_trait]
9pub trait IoTRepository: Send + Sync {
10 async fn create_reading(&self, reading: &IoTReading) -> Result<IoTReading, String>;
16
17 async fn create_readings_bulk(&self, readings: &[IoTReading]) -> Result<usize, String>;
19
20 async fn find_readings_by_building(
22 &self,
23 building_id: Uuid,
24 device_type: Option<DeviceType>,
25 metric_type: Option<MetricType>,
26 start_date: DateTime<Utc>,
27 end_date: DateTime<Utc>,
28 limit: Option<usize>,
29 ) -> Result<Vec<IoTReading>, String>;
30
31 async fn get_consumption_stats(
33 &self,
34 building_id: Uuid,
35 metric_type: MetricType,
36 start_date: DateTime<Utc>,
37 end_date: DateTime<Utc>,
38 ) -> Result<ConsumptionStatsDto, String>;
39
40 async fn get_daily_aggregates(
42 &self,
43 building_id: Uuid,
44 device_type: DeviceType,
45 metric_type: MetricType,
46 start_date: DateTime<Utc>,
47 end_date: DateTime<Utc>,
48 ) -> Result<Vec<DailyAggregateDto>, String>;
49
50 async fn get_monthly_aggregates(
52 &self,
53 building_id: Uuid,
54 device_type: DeviceType,
55 metric_type: MetricType,
56 start_date: DateTime<Utc>,
57 end_date: DateTime<Utc>,
58 ) -> Result<Vec<MonthlyAggregateDto>, String>;
59
60 async fn detect_anomalies(
62 &self,
63 building_id: Uuid,
64 metric_type: MetricType,
65 threshold_percentage: f64,
66 lookback_days: i64,
67 ) -> Result<Vec<IoTReading>, String>;
68
69 async fn create_linky_device(&self, device: &LinkyDevice) -> Result<LinkyDevice, String>;
75
76 async fn find_linky_device_by_id(&self, device_id: Uuid)
78 -> Result<Option<LinkyDevice>, String>;
79
80 async fn find_linky_device_by_building(
82 &self,
83 building_id: Uuid,
84 ) -> Result<Option<LinkyDevice>, String>;
85
86 async fn find_linky_device_by_prm(
88 &self,
89 prm: &str,
90 provider: &str,
91 ) -> Result<Option<LinkyDevice>, String>;
92
93 async fn update_linky_device(&self, device: &LinkyDevice) -> Result<LinkyDevice, String>;
95
96 async fn delete_linky_device(&self, device_id: Uuid) -> Result<(), String>;
98
99 async fn find_devices_needing_sync(&self) -> Result<Vec<LinkyDevice>, String>;
101
102 async fn find_devices_with_expired_tokens(&self) -> Result<Vec<LinkyDevice>, String>;
104}