use std::{fs, path::Path};
use typify::{TypeSpace, TypeSpaceSettings};
const SCHEMA_URL: &'static str = "https://raw.githubusercontent.com/versa-protocol/schema";
const SCHEMA_PATH: &'static str = "data/receipt.schema.json";
fn main() {
let schema_url = format!("{}/{}/{}", SCHEMA_URL, "1.4.0", SCHEMA_PATH);
let content = reqwest::blocking::get(&schema_url).unwrap().text().unwrap();
let schema = serde_json::from_str::<schemars::schema::RootSchema>(&content).unwrap();
let mut type_space = TypeSpace::new(TypeSpaceSettings::default().with_struct_builder(true));
type_space.add_root_schema(schema).unwrap();
let contents =
prettyplease::unparse(&syn::parse2::<syn::File>(type_space.to_stream()).unwrap()).replace("chrono::naive::NaiveDate", "String");
let mut out_file = Path::new("src").to_path_buf();
out_file.push("receipt.rs");
fs::write(out_file, contents).unwrap();
}