use crate::domain::{Granularity, IntensityStats, Region, RollupBucket, TimeRange};
use crate::ports::IntensityRepository;
use super::ApplicationError;
pub struct GetIntensityStats<R: IntensityRepository> {
repository: R,
methodology_id: String,
}
impl<R: IntensityRepository> GetIntensityStats<R> {
pub fn new(repository: R, methodology_id: impl Into<String>) -> Self {
Self {
repository,
methodology_id: methodology_id.into(),
}
}
pub async fn summary(
&self,
region: Region,
range: TimeRange,
) -> Result<Option<IntensityStats>, ApplicationError> {
Ok(self
.repository
.stats(region, &self.methodology_id, range)
.await?)
}
pub async fn series(
&self,
region: Region,
range: TimeRange,
granularity: Granularity,
) -> Result<Vec<RollupBucket>, ApplicationError> {
Ok(self
.repository
.rollup(region, &self.methodology_id, range, granularity)
.await?)
}
}