/**************************************************************************/
/*  aethex_exporter.h                                                     */
/**************************************************************************/
/*                         This file is part of:                          */
/*                          AETHEX ENGINE                                 */
/*                     https://aethex.foundation                          */
/**************************************************************************/
/* Copyright (c) 2026-present AeThex Labs.                                */
/**************************************************************************/

#ifndef AETHEX_EXPORTER_H
#define AETHEX_EXPORTER_H

#include "../aethex_compiler.h"
#include "../aethex_parser.h"
#include "core/object/ref_counted.h"
#include "core/io/file_access.h"

// ==========================================
// AeThex Cross-Platform Exporter
// ==========================================
// Exports AeThex projects to multiple targets:
// - Roblox Studio (Luau)
// - UEFN (Verse)
// - Unity (C#)
// - Web (JavaScript/HTML5)
// ==========================================

class AeThexExporter : public RefCounted {
	GDCLASS(AeThexExporter, RefCounted);

public:
	enum ExportTarget {
		EXPORT_ROBLOX,    // Roblox Studio - generates Luau scripts + rbxlx project
		EXPORT_UEFN,      // UEFN - generates Verse scripts + .uproject
		EXPORT_UNITY,     // Unity - generates C# scripts + .unitypackage
		EXPORT_WEB,       // Web - generates JS/HTML5 bundle
		EXPORT_ALL,       // Generate all targets
	};

	struct ExportOptions {
		String output_path;
		String project_name;
		bool minify = false;
		bool generate_sourcemaps = false;
		bool include_runtime = true;
		Vector<String> excluded_files;
		
		// Platform-specific options
		String roblox_game_id;
		String uefn_project_name;
		String unity_namespace = "AeThex";
	};

	struct ExportResult {
		bool success = false;
		String error_message;
		Vector<String> generated_files;
		Dictionary warnings;
	};

private:
	ExportOptions options;
	AeThexCompiler compiler;
	
	// Platform-specific generators
	ExportResult export_to_roblox(const Vector<String> &source_files);
	ExportResult export_to_uefn(const Vector<String> &source_files);
	ExportResult export_to_unity(const Vector<String> &source_files);
	ExportResult export_to_web(const Vector<String> &source_files);
	
	// Generate platform-specific project files
	String generate_roblox_project(const String &project_name);
	String generate_uefn_project(const String &project_name);
	String generate_unity_asmdef(const String &namespace_name);
	String generate_web_html(const String &project_name);
	
	// Helpers
	String read_aethex_file(const String &path);
	Error write_output_file(const String &path, const String &content);
	Vector<String> collect_source_files(const String &dir);

protected:
	static void _bind_methods();

public:
	AeThexExporter();
	~AeThexExporter();
	
	// Main export function
	ExportResult export_project(const String &project_dir, ExportTarget target, const ExportOptions &p_options);
	
	// Single file export
	String export_file(const String &source_path, ExportTarget target);
	
	// Get available targets for a source file
	Vector<String> get_supported_targets(const String &source_path);
	
	// Options
	void set_options(const ExportOptions &p_options) { options = p_options; }
	ExportOptions get_options() const { return options; }
};

VARIANT_ENUM_CAST(AeThexExporter::ExportTarget);

#endif // AETHEX_EXPORTER_H
