98 lines
3.6 KiB
C#
98 lines
3.6 KiB
C#
namespace Heimdall.Domain.Entities;
|
|
|
|
/// <summary>
|
|
/// Global application setting (key-value). Stored in DB and pushed to all agents
|
|
/// in real-time via SignalR. Overridable per-agent via AgentSetting.
|
|
/// </summary>
|
|
public class AppSetting
|
|
{
|
|
public Guid Id { get; private set; } = Guid.NewGuid();
|
|
|
|
/// <summary>Unique setting key (e.g. "heartbeat.interval.seconds", "log.level", "ai.detection.enabled").</summary>
|
|
public string Key { get; private set; } = string.Empty;
|
|
|
|
/// <summary>Setting value as a JSON-serializable string.</summary>
|
|
public string Value { get; private set; } = string.Empty;
|
|
|
|
/// <summary>Human-readable description of what this setting controls.</summary>
|
|
public string? Description { get; private set; }
|
|
|
|
/// <summary>Category for UI grouping (e.g. "Heartbeat", "Logging", "AI", "Recording").</summary>
|
|
public string Category { get; private set; } = "General";
|
|
|
|
/// <summary>Value type hint for UI rendering ("string", "int", "bool", "double", "select").</summary>
|
|
public string ValueType { get; private set; } = "string";
|
|
|
|
/// <summary>For select types, comma-separated allowed values.</summary>
|
|
public string? AllowedValues { get; private set; }
|
|
|
|
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
|
public DateTime UpdatedAt { get; private set; } = DateTime.UtcNow;
|
|
|
|
private AppSetting() { } // EF Core
|
|
|
|
public AppSetting(string key, string value, string category = "General", string? description = null)
|
|
{
|
|
Key = !string.IsNullOrWhiteSpace(key) ? key.Trim().ToLowerInvariant()
|
|
: throw new ArgumentException("Key is required", nameof(key));
|
|
Value = value ?? string.Empty;
|
|
Category = category;
|
|
Description = description;
|
|
}
|
|
|
|
public void UpdateValue(string value)
|
|
{
|
|
Value = value ?? string.Empty;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
|
|
public void UpdateMetadata(string? description, string? category, string? valueType, string? allowedValues)
|
|
{
|
|
if (description is not null) Description = description;
|
|
if (category is not null) Category = category;
|
|
if (valueType is not null) ValueType = valueType;
|
|
if (allowedValues is not null) AllowedValues = allowedValues;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Per-agent setting override. Takes precedence over AppSetting for a specific agent.
|
|
/// When created/updated, a SignalR notification is sent to the affected agent.
|
|
/// </summary>
|
|
public class AgentSetting
|
|
{
|
|
public Guid Id { get; private set; } = Guid.NewGuid();
|
|
|
|
/// <summary>Foreign key to the Agent this setting applies to.</summary>
|
|
public Guid AgentId { get; private set; }
|
|
|
|
/// <summary>Setting key (same namespace as AppSetting keys).</summary>
|
|
public string Key { get; private set; } = string.Empty;
|
|
|
|
/// <summary>Override value for this specific agent.</summary>
|
|
public string Value { get; private set; } = string.Empty;
|
|
|
|
public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
|
|
public DateTime UpdatedAt { get; private set; } = DateTime.UtcNow;
|
|
|
|
// Navigation
|
|
public Agent Agent { get; private set; } = null!;
|
|
|
|
private AgentSetting() { } // EF Core
|
|
|
|
public AgentSetting(Guid agentId, string key, string value)
|
|
{
|
|
AgentId = agentId;
|
|
Key = !string.IsNullOrWhiteSpace(key) ? key.Trim().ToLowerInvariant()
|
|
: throw new ArgumentException("Key is required", nameof(key));
|
|
Value = value ?? string.Empty;
|
|
}
|
|
|
|
public void UpdateValue(string value)
|
|
{
|
|
Value = value ?? string.Empty;
|
|
UpdatedAt = DateTime.UtcNow;
|
|
}
|
|
}
|