koprogo_api/application/ports/
energy_bill_upload_repository.rs

1use async_trait::async_trait;
2use uuid::Uuid;
3
4use crate::domain::entities::EnergyBillUpload;
5
6/// Repository trait for energy bill upload persistence
7#[async_trait]
8pub trait EnergyBillUploadRepository: Send + Sync {
9    /// Create a new energy bill upload
10    async fn create(&self, upload: &EnergyBillUpload) -> Result<EnergyBillUpload, String>;
11
12    /// Find bill upload by ID
13    async fn find_by_id(&self, id: Uuid) -> Result<Option<EnergyBillUpload>, String>;
14
15    /// Find all uploads for a campaign
16    async fn find_by_campaign(&self, campaign_id: Uuid) -> Result<Vec<EnergyBillUpload>, String>;
17
18    /// Find all uploads for a unit
19    async fn find_by_unit(&self, unit_id: Uuid) -> Result<Vec<EnergyBillUpload>, String>;
20
21    /// Find upload for a specific campaign and unit
22    async fn find_by_campaign_and_unit(
23        &self,
24        campaign_id: Uuid,
25        unit_id: Uuid,
26    ) -> Result<Option<EnergyBillUpload>, String>;
27
28    /// Find all uploads by the user who uploaded them
29    async fn find_by_uploaded_by(&self, uploaded_by: Uuid)
30        -> Result<Vec<EnergyBillUpload>, String>;
31
32    /// Find uploads by building
33    async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<EnergyBillUpload>, String>;
34
35    /// Update bill upload
36    async fn update(&self, upload: &EnergyBillUpload) -> Result<EnergyBillUpload, String>;
37
38    /// Delete bill upload (soft delete)
39    async fn delete(&self, id: Uuid) -> Result<(), String>;
40
41    /// Find uploads that need auto-deletion (retention period expired)
42    async fn find_expired(&self) -> Result<Vec<EnergyBillUpload>, String>;
43
44    /// Get count of verified uploads for a campaign (for k-anonymity check)
45    async fn count_verified_by_campaign(&self, campaign_id: Uuid) -> Result<i32, String>;
46
47    /// Find all verified, non-deleted uploads for a campaign (for aggregation)
48    async fn find_verified_by_campaign(
49        &self,
50        campaign_id: Uuid,
51    ) -> Result<Vec<EnergyBillUpload>, String>;
52
53    /// Batch delete expired bills (GDPR auto-cleanup)
54    async fn delete_expired(&self) -> Result<i32, String>;
55}