use crate::blueprint::constructor::CloningStrategy;
use crate::blueprint::conversions::{cloning2cloning, lint2lint, raw_callable2registered_callable};
use crate::blueprint::linter::Lint;
use crate::blueprint::reflection::RawCallable;
use pavex_bp_schema::{Blueprint as BlueprintSchema, LintSetting};
use pavex_bp_schema::{Component, Constructor};
pub struct RegisteredConstructor<'a> {
pub(crate) blueprint: &'a mut BlueprintSchema,
pub(crate) component_id: usize,
}
impl<'a> RegisteredConstructor<'a> {
#[track_caller]
pub fn error_handler(mut self, error_handler: RawCallable) -> Self {
let callable = raw_callable2registered_callable(error_handler);
self.constructor().error_handler = Some(callable);
self
}
pub fn cloning(mut self, strategy: CloningStrategy) -> Self {
self.constructor().cloning_strategy = Some(cloning2cloning(strategy));
self
}
pub fn ignore(mut self, lint: Lint) -> Self {
self.constructor()
.lints
.insert(lint2lint(lint), LintSetting::Ignore);
self
}
pub fn enforce(mut self, lint: Lint) -> Self {
self.constructor()
.lints
.insert(lint2lint(lint), LintSetting::Enforce);
self
}
fn constructor(&mut self) -> &mut Constructor {
let component = &mut self.blueprint.components[self.component_id];
let Component::Constructor(c) = component else {
unreachable!("The component should be a constructor")
};
c
}
}