use crate::expr::FieldSpec;
use std::borrow::Cow;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum RetrySafety {
Idempotent,
NotIdempotent,
#[default]
Unknown,
}
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct Reference {
pub field: Cow<'static, str>,
pub kind: Cow<'static, str>,
}
impl Reference {
pub fn new(field: impl Into<Cow<'static, str>>, kind: impl Into<Cow<'static, str>>) -> Self {
Self {
field: field.into(),
kind: kind.into(),
}
}
}
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct FunctionSpec {
pub description: Cow<'static, str>,
pub category: Cow<'static, str>,
pub retry: RetrySafety,
pub references: Vec<Reference>,
pub runtime_fields: Option<Vec<FieldSpec>>,
}
impl FunctionSpec {
#[must_use]
pub fn with_description(mut self, description: impl Into<Cow<'static, str>>) -> Self {
self.description = description.into();
self
}
#[must_use]
pub fn with_category(mut self, category: impl Into<Cow<'static, str>>) -> Self {
self.category = category.into();
self
}
#[must_use]
pub fn with_retry(mut self, retry: RetrySafety) -> Self {
self.retry = retry;
self
}
#[must_use]
pub fn with_references(mut self, references: Vec<Reference>) -> Self {
self.references = references;
self
}
#[must_use]
pub fn with_runtime_fields(mut self, fields: Vec<FieldSpec>) -> Self {
self.runtime_fields = Some(fields);
self
}
}