using MemoryPack;

namespace Insight.Agent.Messages
{
    [MemoryPackUnion(100, typeof(Update))]
    [MemoryPackUnion(101, typeof(UpdateList))]
    public partial interface IAgentMessage { }

    [MemoryPackable]
    public partial class Update : IAgentMessage
    {
        [MemoryPackOrder(0)]
        public string? Id { get; set; }

        [MemoryPackOrder(1)]
        public DateTime? Date { get; set; }

        [MemoryPackOrder(2)]
        public string? Name { get; set; }

        [MemoryPackOrder(3)]
        public string? Description { get; set; }

        [MemoryPackOrder(4)]
        public string? SupportUrl { get; set; }

        [MemoryPackOrder(5)]
        public string? Hotfix { get; set; }

        // if installed
        [MemoryPackOrder(6)]
        public OsUpdateResultCodeEnum? Result { get; set; }

        // if pending
        [MemoryPackOrder(7)]
        public OsUpdateTypeEnum? Type { get; set; }

        [MemoryPackOrder(8)]
        public decimal? Size { get; set; }

        [MemoryPackOrder(9)]
        public bool? IsDownloaded { get; set; }

        [MemoryPackOrder(10)]
        public bool? CanRequestUserInput { get; set; }

        [MemoryPackOrder(11)]
        public OsUpdateRebootBehaviorEnum? RebootBehavior { get; set; }

        public enum OsUpdateRebootBehaviorEnum
        {
            NeverReboots = 1,
            AlwaysRequiresReboot = 2,
            CanRequestReboot = 3
        }

        public enum OsUpdateResultCodeEnum
        {
            NotStarted = 1,
            InProgress = 2,
            Succeeded = 3,
            SucceededWithErrors = 4,
            Failed = 5,
            Aborted = 6
        }

        public enum OsUpdateTypeEnum
        {
            Software = 1,
            Driver = 2
        }
    }

    [MemoryPackable]
    public partial class UpdateList : IAgentMessage
    {
        [MemoryPackOrder(0)]
        public List<Update>? Installed { get; set; }

        [MemoryPackOrder(1)]
        public List<Update>? Pending { get; set; }
    }
}