koprogo_api/application/ports/
energy_campaign_repository.rs

1use async_trait::async_trait;
2use uuid::Uuid;
3
4use crate::domain::entities::{EnergyCampaign, ProviderOffer};
5
6/// Repository trait for energy campaign persistence
7#[async_trait]
8pub trait EnergyCampaignRepository: Send + Sync {
9    /// Create a new energy campaign
10    async fn create(&self, campaign: &EnergyCampaign) -> Result<EnergyCampaign, String>;
11
12    /// Find campaign by ID
13    async fn find_by_id(&self, id: Uuid) -> Result<Option<EnergyCampaign>, String>;
14
15    /// Find all campaigns for an organization
16    async fn find_by_organization(
17        &self,
18        organization_id: Uuid,
19    ) -> Result<Vec<EnergyCampaign>, String>;
20
21    /// Find all campaigns for a building
22    async fn find_by_building(&self, building_id: Uuid) -> Result<Vec<EnergyCampaign>, String>;
23
24    /// Update campaign
25    async fn update(&self, campaign: &EnergyCampaign) -> Result<EnergyCampaign, String>;
26
27    /// Delete campaign
28    async fn delete(&self, id: Uuid) -> Result<(), String>;
29
30    /// Add provider offer to campaign
31    async fn add_offer(
32        &self,
33        campaign_id: Uuid,
34        offer: &ProviderOffer,
35    ) -> Result<ProviderOffer, String>;
36
37    /// Get all offers for a campaign
38    async fn get_offers(&self, campaign_id: Uuid) -> Result<Vec<ProviderOffer>, String>;
39
40    /// Update provider offer
41    async fn update_offer(&self, offer: &ProviderOffer) -> Result<ProviderOffer, String>;
42
43    /// Delete provider offer
44    async fn delete_offer(&self, offer_id: Uuid) -> Result<(), String>;
45
46    /// Get offer by ID
47    async fn find_offer_by_id(&self, offer_id: Uuid) -> Result<Option<ProviderOffer>, String>;
48
49    /// Update campaign aggregated statistics (total_kwh, participants, etc.)
50    async fn update_aggregation(
51        &self,
52        campaign_id: Uuid,
53        total_kwh_electricity: Option<f64>,
54        total_kwh_gas: Option<f64>,
55        avg_kwh_per_unit: Option<f64>,
56    ) -> Result<(), String>;
57}