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 uploads by building
29    async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<EnergyBillUpload>, String>;
30
31    /// Update bill upload
32    async fn update(&self, upload: &EnergyBillUpload) -> Result<EnergyBillUpload, String>;
33
34    /// Delete bill upload (soft delete)
35    async fn delete(&self, id: Uuid) -> Result<(), String>;
36
37    /// Find uploads that need auto-deletion (retention period expired)
38    async fn find_expired(&self) -> Result<Vec<EnergyBillUpload>, String>;
39
40    /// Get count of verified uploads for a campaign (for k-anonymity check)
41    async fn count_verified_by_campaign(&self, campaign_id: Uuid) -> Result<i32, String>;
42
43    /// Find all verified, non-deleted uploads for a campaign (for aggregation)
44    async fn find_verified_by_campaign(
45        &self,
46        campaign_id: Uuid,
47    ) -> Result<Vec<EnergyBillUpload>, String>;
48
49    /// Batch delete expired bills (GDPR auto-cleanup)
50    async fn delete_expired(&self) -> Result<i32, String>;
51}