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

#ifndef AETHEX_PLATFORM_EXPORTER_H
#define AETHEX_PLATFORM_EXPORTER_H

#include "core/object/ref_counted.h"
#include "core/string/ustring.h"
#include "core/io/dir_access.h"
#include "export_config.h"

// Base class for platform-specific exporters
class AeThexPlatformExporter : public RefCounted {
	GDCLASS(AeThexPlatformExporter, RefCounted);

public:
	enum ExportResult {
		RESULT_SUCCESS,
		RESULT_ERROR_INVALID_CONFIG,
		RESULT_ERROR_COMPILE_FAILED,
		RESULT_ERROR_WRITE_FAILED,
		RESULT_ERROR_PLATFORM_SPECIFIC,
	};

	struct ExportStats {
		int scripts_compiled = 0;
		int assets_processed = 0;
		int errors = 0;
		int warnings = 0;
		int64_t output_size = 0;
		double compile_time = 0;
	};

protected:
	Ref<AeThexExportConfig> config;
	String output_path;
	ExportStats stats;
	PackedStringArray error_messages;
	PackedStringArray warning_messages;

	static void _bind_methods();
	
	void _log_error(const String &p_message);
	void _log_warning(const String &p_message);
	void _log_info(const String &p_message);
	void _export_directory(Ref<DirAccess> p_dir, const String &p_source_base, const String &p_output_base);

public:
	// Abstract methods to implement
	virtual AeThexExportConfig::Platform get_platform() const = 0;
	virtual String get_platform_name() const = 0;
	virtual String get_file_extension() const = 0;
	
	virtual ExportResult export_project(const String &p_output_path);
	virtual ExportResult compile_script(const String &p_source, String &r_output);
	virtual ExportResult process_asset(const String &p_asset_path, const String &p_output_path);
	
	// Configuration
	void set_config(const Ref<AeThexExportConfig> &p_config);
	Ref<AeThexExportConfig> get_config() const { return config; }
	
	// Results
	ExportStats get_stats() const { return stats; }
	PackedStringArray get_errors() const { return error_messages; }
	PackedStringArray get_warnings() const { return warning_messages; }
	void clear_messages();

	AeThexPlatformExporter();
	virtual ~AeThexPlatformExporter();
};

VARIANT_ENUM_CAST(AeThexPlatformExporter::ExportResult);

#endif // AETHEX_PLATFORM_EXPORTER_H
