use super::VaporFacts;
use crate::decision::{DecisionBuildError, DecisionTables, NativeAnalysis, build};
use vize_l2::{
artifact::Artifact,
file::FileArtifact,
lang::js::{NativeSelectedSetup, NativeTemplateFile, NativeTemplateView},
};
pub struct NativeSelectedSetupVaporAnalysis<'view, 'owner, 'arena> {
setup: &'view NativeSelectedSetup<'owner, 'arena>,
template: NativeTemplateView<'owner, 'arena>,
analysis: NativeAnalysis<'owner, 'arena>,
}
impl<'view, 'owner, 'arena> NativeSelectedSetupVaporAnalysis<'view, 'owner, 'arena> {
#[must_use]
pub fn setup(&self) -> &'view NativeSelectedSetup<'owner, 'arena> {
self.setup
}
#[must_use]
pub fn owner(&self) -> &'owner NativeTemplateFile<'arena> {
self.template.owner()
}
#[must_use]
pub fn file(&self) -> &'owner FileArtifact<'arena> {
self.setup.file()
}
#[must_use]
pub fn original_attributes(
&self,
) -> Option<&crate::decision::OriginalAttributeFacts<'owner, 'arena>> {
self.analysis.original_attributes()
}
#[must_use]
pub fn artifact(&self) -> &'owner Artifact<'arena> {
self.file().artifact()
}
#[must_use]
pub fn tables(&self) -> &DecisionTables {
self.analysis.tables()
}
#[must_use]
pub fn vapor(&self) -> Option<&VaporFacts<'owner, 'arena>> {
self.analysis.vapor()
}
}
pub fn build_native_selected_setup_vapor_decisions<'view, 'owner, 'arena>(
setup: &'view NativeSelectedSetup<'owner, 'arena>,
) -> Result<NativeSelectedSetupVaporAnalysis<'view, 'owner, 'arena>, DecisionBuildError> {
let template = setup
.owner()
.view()
.map_err(|_| DecisionBuildError::IncompleteFile)?;
let file = template.file().ok_or(DecisionBuildError::IncompleteFile)?;
if !core::ptr::eq(file, setup.file()) {
return Err(DecisionBuildError::IncompleteFile);
}
let analysis = build::build_with_vapor_setup(setup)?;
Ok(NativeSelectedSetupVaporAnalysis {
setup,
template,
analysis,
})
}