/*
 * Copyright 2026 TELAMIN LIMITED
 * SPDX-License-Identifier: Apache-2.0
 * Demonstration code; see LICENSE-APACHE-2.0.txt and NOTICE.txt.
 */
package demo.authoring;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.telamin.fluxtion.Fluxtion;
import com.telamin.fluxtion.runtime.audit.EventLogControlEvent.LogLevel;
public class GenerateApplication {
    public static void main(String[] args) throws Exception {
        Path output = Paths.get(args[0]);
        Files.createDirectories(output);
        StringWriter source = new StringWriter();
        StringWriter graph = new StringWriter();
        Decision root = new Decision(new LimitComparison(new Calculation(new OrderInput())));
        Fluxtion.compile(application -> {
            application.addNode(root, "decision");
            application.addEventAudit(LogLevel.INFO);
        }, config -> {
            config.setPackageName("demo.authoring.generated");
            config.setClassName("OrderProcessor");
            config.setSourceWriter(source);
            config.setGraphmlWriter(graph);
            config.setFormatSource(false);
        });
        Files.write(output.resolve("OrderProcessor.java"), source.toString().getBytes(StandardCharsets.UTF_8));
        Files.write(output.resolve("OrderProcessor.graphml"), graph.toString().getBytes(StandardCharsets.UTF_8));
        System.out.println("Generated OrderProcessor.java and OrderProcessor.graphml");
    }
}
