use serde::{Deserialize, Serialize};
use xpile_contracts::{Contract, ContractFormat, ContractId};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ContractRenderConfig {
pub format: ContractFormat,
pub embed_citation: bool,
pub include_falsification: bool,
pub lean_version: Option<(u32, u32)>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RenderedDoc {
pub primary: String,
pub sidecars: Vec<(String, Vec<u8>)>,
pub citations: Vec<ContractId>,
}
#[derive(Debug, thiserror::Error)]
pub enum ContractBackendError {
#[error("unsupported format for this backend: {0:?}")]
UnsupportedFormat(ContractFormat),
#[error("unsupported Lean version: {0:?} (only Lean 4 is supported)")]
UnsupportedLeanVersion(Option<(u32, u32)>),
#[error("rendering error: {0}")]
Render(String),
#[error("citation bridge violation: {0}")]
CitationBridge(String),
}
pub trait ContractBackend: Send + Sync {
fn name(&self) -> &'static str;
fn formats(&self) -> &[ContractFormat];
fn render(
&self,
contract: &Contract,
config: &ContractRenderConfig,
) -> Result<RenderedDoc, ContractBackendError>;
}