use std::path::Path;
use bumpalo::Bump;
use orrery::{DiagramBuilder, InMemorySourceProvider, config::AppConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let source = r#"
diagram component;
// Define custom types
type Database = Rectangle [fill_color="lightblue"];
type Service = Rectangle [fill_color="lightyellow"];
// Create components
frontend as "Frontend App": Service;
backend as "Backend API": Service;
database as "PostgreSQL": Database;
// Define relationships
frontend -> backend: "REST API";
backend -> database: "SQL queries";
"#;
let mut provider = InMemorySourceProvider::new();
provider.add_file("example.orr", source);
let builder = DiagramBuilder::new(AppConfig::default(), &provider);
println!("Parsing diagram from source...");
let arena = Bump::new();
let diagram = builder
.parse(&arena, Path::new("example.orr"))
.map_err(|e| e.to_string())?;
println!("Diagram kind: {:?}", diagram.kind());
println!("Layout engine: {:?}", diagram.layout_engine());
println!("Number of elements: {}", diagram.scope().elements().len());
println!("\nRendering to SVG...");
let svg = builder.render_svg(&diagram)?;
println!("SVG generated successfully!");
println!("SVG length: {} bytes", svg.len());
let output_path = "from_source_output.svg";
std::fs::write(output_path, &svg)?;
println!("SVG written to: {}", output_path);
Ok(())
}