using System.Reflection;
using System.Text;
using System; // Required for Exception
namespace SessionZero.Data;
public class SzfGenerator
{
private readonly SzfGeneratorOptions _options;
public SzfGenerator(SzfGeneratorOptions? options = null)
{
_options = options ?? new SzfGeneratorOptions();
}
///
/// Generate SZF content from any SzfObject
///
public string Generate(SzfObject obj)
{
var builder = new StringBuilder();
var writer = new SzfFieldWriter(builder, _options);
// Generate header
GenerateHeader(writer, obj);
// Generate type-specific metadata and content
// These methods delegate to the SzfObject itself,
// which now correctly accesses its own Metadata.
obj.GenerateMetadata(writer); // This now handles writing the standard metadata section
obj.GenerateContent(writer); // This handles writing object-specific content sections
return builder.ToString();
}
///
/// Generate the SZF header (!type: and !schema:)
///
private void GenerateHeader(SzfFieldWriter writer, SzfObject obj)
{
// TypeIdentifier is now directly accessible from the SzfObject base class
writer.Builder.AppendLine($"!type: {obj.TypeIdentifier}");
// Schema version is a fixed format version, not object-specific metadata
writer.Builder.AppendLine($"!schema: 1.0.0"); // Assuming current schema version is 1.0.0
writer.Builder.AppendLine();
}
}
///
/// Configuration options for SZF generation
///
public class SzfGeneratorOptions
{
///
/// Whether to indent field lines within sections
///
public bool IndentFields { get; set; } = false;
///
/// Indent string to use for fields (if IndentFields is true)
///
public string Indent { get; set; } = " ";
///
/// Whether to include empty sections
///
public bool IncludeEmptySections { get; set; } = false;
///
/// Whether to include fields with null/empty values
///
public bool IncludeEmptyFields { get; set; } = true;
}
///
/// Exception thrown during SZF generation
///
public class SzfGenerateException : Exception
{
public SzfGenerateException(string message) : base(message)
{
}
public SzfGenerateException(string message, Exception innerException) : base(message, innerException)
{
}
}