133 lines
3.7 KiB
C#
133 lines
3.7 KiB
C#
namespace SessionZero.Data;
|
|
|
|
public class Dataset : SzfObject
|
|
{
|
|
public string DatasetType { get; set; } = string.Empty;
|
|
public string ImageUrl { get; set; } = string.Empty;
|
|
|
|
// Collection of entries within this dataset
|
|
public List<DatasetEntry> Entries { get; set; } = [];
|
|
|
|
// Additional metadata fields for .szf compatibility
|
|
public Dictionary<string, object> Metadata { get; set; } = new();
|
|
|
|
public override SzfObjectType ObjectType => SzfObjectType.Dataset;
|
|
|
|
public override void PopulateFromMetadata(Dictionary<string, SzfField> metadata)
|
|
{
|
|
// Call base method to populate common fields
|
|
base.PopulateFromMetadata(metadata);
|
|
|
|
// Populate dataset-specific fields
|
|
if (metadata.TryGetValue("Type", out var typeField))
|
|
DatasetType = typeField.Value?.ToString() ?? string.Empty;
|
|
|
|
if (metadata.TryGetValue("ImageUrl", out var imageField))
|
|
ImageUrl = imageField.Value?.ToString() ?? string.Empty;
|
|
}
|
|
|
|
public override SzfValidationResult Validate()
|
|
{
|
|
var result = base.Validate();
|
|
|
|
if (string.IsNullOrWhiteSpace(DatasetType))
|
|
result.AddError("DatasetType is required");
|
|
|
|
// Validate entries
|
|
var entryNames = new HashSet<string>();
|
|
foreach (var entry in Entries)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(entry.Name))
|
|
{
|
|
result.AddError("All entries must have a name");
|
|
continue;
|
|
}
|
|
|
|
if (!entryNames.Add(entry.Name))
|
|
result.AddError($"Duplicate entry name: {entry.Name}");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class DatasetEntry
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
public List<DatasetField> Fields { get; set; } = [];
|
|
public List<DatasetSection> Sections { get; set; } = [];
|
|
}
|
|
|
|
public class DatasetSection
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
public List<DatasetField> Fields { get; set; } = [];
|
|
public List<DatasetSection> Subsections { get; set; } = [];
|
|
}
|
|
|
|
public class DatasetField
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
public DatasetFieldType Type { get; set; }
|
|
public object? Value { get; set; } = null;
|
|
public string? Description { get; set; }
|
|
public bool IsRequired { get; set; } = false;
|
|
public object? DefaultValue { get; set; }
|
|
|
|
// For calculated fields
|
|
public string? Formula { get; set; }
|
|
|
|
// For dataset reference fields
|
|
public string? ReferencedDatasetId { get; set; }
|
|
public string? ReferencedDatasetType { get; set; }
|
|
public bool AllowMultiple { get; set; } = false;
|
|
|
|
// For group fields
|
|
public List<DatasetField> GroupFields { get; set; } = [];
|
|
}
|
|
|
|
public enum DatasetFieldType
|
|
{
|
|
Text,
|
|
TextField,
|
|
Number,
|
|
Boolean,
|
|
Group,
|
|
Calculated,
|
|
System,
|
|
DatasetReference,
|
|
DatasetType,
|
|
DatasetReferenceMultiple,
|
|
DatasetTypeMultiple
|
|
}
|
|
|
|
// Supporting classes for dataset management
|
|
public class DatasetReference
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
public Guid DatasetId { get; set; }
|
|
public string Version { get; set; } = string.Empty;
|
|
|
|
public override string ToString() => $"{Name}|{DatasetId}|{Version}";
|
|
|
|
public static DatasetReference? Parse(string reference)
|
|
{
|
|
var parts = reference.Split('|');
|
|
if (parts.Length != 3 || !Guid.TryParse(parts[1], out var id))
|
|
return null;
|
|
|
|
return new DatasetReference
|
|
{
|
|
Name = parts[0],
|
|
DatasetId = id,
|
|
Version = parts[2]
|
|
};
|
|
}
|
|
}
|
|
|
|
public class DatasetValidationResult
|
|
{
|
|
public bool IsValid { get; set; }
|
|
public List<string> Errors { get; set; } = [];
|
|
public List<string> Warnings { get; set; } = [];
|
|
} |