Skip to main content

coil_ops/reports/
planning.rs

1use crate::error::OpsModelError;
2use crate::identifiers::{ReportExportId, ReportId};
3use crate::validation::require_non_empty;
4use coil_auth::Capability;
5use coil_jobs::{IdempotencyKey, JobInstant, JobSpec, PlannedJob};
6
7use super::ReportDefinition;
8
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct ReportParameter {
11    pub key: String,
12    pub value: String,
13}
14
15impl ReportParameter {
16    pub fn new(key: impl Into<String>, value: impl Into<String>) -> Result<Self, OpsModelError> {
17        Ok(Self {
18            key: require_non_empty("report_parameter_key", key.into())?,
19            value: require_non_empty("report_parameter_value", value.into())?,
20        })
21    }
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
25pub struct ReportExportRequest {
26    pub export_id: ReportExportId,
27    pub report_id: ReportId,
28    pub requested_by: String,
29    pub requested_at: JobInstant,
30    pub scheduled_for: Option<JobInstant>,
31    pub idempotency_key: Option<IdempotencyKey>,
32    pub operator_capabilities: Vec<Capability>,
33    pub parameters: Vec<ReportParameter>,
34}
35
36impl ReportExportRequest {
37    pub fn new(
38        export_id: ReportExportId,
39        report_id: ReportId,
40        requested_by: impl Into<String>,
41        requested_at: JobInstant,
42    ) -> Result<Self, OpsModelError> {
43        Ok(Self {
44            export_id,
45            report_id,
46            requested_by: require_non_empty("report_requested_by", requested_by.into())?,
47            requested_at,
48            scheduled_for: None,
49            idempotency_key: None,
50            operator_capabilities: Vec::new(),
51            parameters: Vec::new(),
52        })
53    }
54
55    pub fn scheduled_for(mut self, instant: JobInstant) -> Self {
56        self.scheduled_for = Some(instant);
57        self
58    }
59
60    pub fn with_idempotency_key(mut self, key: IdempotencyKey) -> Self {
61        self.idempotency_key = Some(key);
62        self
63    }
64
65    pub fn with_capability(mut self, capability: Capability) -> Self {
66        self.operator_capabilities.push(capability);
67        self
68    }
69
70    pub fn with_parameter(mut self, parameter: ReportParameter) -> Self {
71        self.parameters.push(parameter);
72        self
73    }
74}
75
76#[derive(Debug, Clone, PartialEq, Eq)]
77pub struct ReportExportPlan {
78    pub definition: ReportDefinition,
79    pub job: JobSpec,
80    pub planned_job: PlannedJob,
81    pub output_object_key: String,
82    pub parameters: Vec<ReportParameter>,
83}