namespace Heimdall.Domain.Entities;
///
/// Global application setting (key-value). Stored in DB and pushed to all agents
/// in real-time via SignalR. Overridable per-agent via AgentSetting.
///
public class AppSetting
{
public Guid Id { get; private set; } = Guid.NewGuid();
/// Unique setting key (e.g. "heartbeat.interval.seconds", "log.level", "ai.detection.enabled").
public string Key { get; private set; } = string.Empty;
/// Setting value as a JSON-serializable string.
public string Value { get; private set; } = string.Empty;
/// Human-readable description of what this setting controls.
public string? Description { get; private set; }
/// Category for UI grouping (e.g. "Heartbeat", "Logging", "AI", "Recording").
public string Category { get; private set; } = "General";
/// Value type hint for UI rendering ("string", "int", "bool", "double", "select").
public string ValueType { get; private set; } = "string";
/// For select types, comma-separated allowed values.
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;
}
}
///
/// Per-agent setting override. Takes precedence over AppSetting for a specific agent.
/// When created/updated, a SignalR notification is sent to the affected agent.
///
public class AgentSetting
{
public Guid Id { get; private set; } = Guid.NewGuid();
/// Foreign key to the Agent this setting applies to.
public Guid AgentId { get; private set; }
/// Setting key (same namespace as AppSetting keys).
public string Key { get; private set; } = string.Empty;
/// Override value for this specific agent.
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;
}
}