using System.Text.Json.Serialization;

namespace NexusShell.Services.Policy;

public sealed class NexusPolicy
{
    [JsonPropertyName("id")]
    public string Id { get; set; } = string.Empty;

    [JsonPropertyName("name")]
    public string Name { get; set; } = string.Empty;

    [JsonPropertyName("role")]
    public string Role { get; set; } = nameof(NexusRole.User);

    [JsonPropertyName("version")]
    public string Version { get; set; } = "1.0";

    [JsonPropertyName("allowApps")]
    public List<string> AllowApps { get; set; } = [];

    [JsonPropertyName("denyApps")]
    public List<string> DenyApps { get; set; } = [];

    [JsonPropertyName("allowFeatures")]
    public List<string> AllowFeatures { get; set; } = [];

    [JsonPropertyName("denyFeatures")]
    public List<string> DenyFeatures { get; set; } = [];

    [JsonPropertyName("allowCommands")]
    public List<string> AllowCommands { get; set; } = [];

    [JsonPropertyName("denyCommands")]
    public List<string> DenyCommands { get; set; } = [];

    [JsonPropertyName("denySettingsSections")]
    public List<string> DenySettingsSections { get; set; } = [];

    [JsonPropertyName("rules")]
    public List<NexusPolicyRule> Rules { get; set; } = [];

    public NexusRole ParsedRole =>
        Enum.TryParse<NexusRole>(Role, ignoreCase: true, out var parsed) ? parsed : NexusRole.User;
}
