namespace NexusShell.Models;

public enum NexusTrustStatus
{
    Trusted,
    Pending,
    Blocked,
    Unknown,
}

public enum NexusDeviceEnrollmentStatus
{
    Unknown,
    Pending,
    Enrolled,
    Blocked,
}

public sealed class NexusOrganizationRecord
{
    public string Id { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class NexusOrganizationOption
{
    public string Id { get; init; } = string.Empty;
    public string Name { get; init; } = string.Empty;
}

public sealed class NexusUserRecord
{
    public string Id { get; set; } = string.Empty;
    public string DisplayName { get; set; } = string.Empty;
    public string OrganizationId { get; set; } = string.Empty;
    public string OrganizationName { get; set; } = string.Empty;
    public DateTimeOffset CreatedAtUtc { get; set; } = DateTimeOffset.UtcNow;
}

public sealed class NexusDeviceRecord
{
    public string DeviceId { get; set; } = string.Empty;
    public string ComputerName { get; set; } = string.Empty;
    public string FriendlyName { get; set; } = string.Empty;
    public string Owner { get; set; } = string.Empty;
    public string Organization { get; set; } = string.Empty;
    public string AgentVersion { get; set; } = string.Empty;
    public string ShellVersion { get; set; } = string.Empty;
    public DateTimeOffset? EnrollmentDate { get; set; }
    public DateTimeOffset? LastSeen { get; set; }
    public NexusDeviceEnrollmentStatus Status { get; set; } = NexusDeviceEnrollmentStatus.Unknown;
}

public sealed class NexusTrustRecord
{
    public string DeviceId { get; set; } = string.Empty;
    public NexusTrustStatus Status { get; set; } = NexusTrustStatus.Unknown;
    public DateTimeOffset? EvaluatedAtUtc { get; set; }
    public string? Reason { get; set; }
}

public sealed class NexusIdentitySnapshot
{
    public NexusOrganizationRecord? Organization { get; init; }
    public NexusUserRecord? User { get; init; }
    public NexusDeviceRecord? Device { get; init; }
    public NexusTrustRecord? Trust { get; init; }
    public bool IsEnrolled { get; init; }
}

public sealed class NexusEnrollmentRequest
{
    public required string OrganizationId { get; init; }
    public required string UserName { get; init; }
    public required string DeviceFriendlyName { get; init; }
}

public sealed class NexusEnrollmentResult
{
    public bool Success { get; init; }
    public string? Error { get; init; }
    public NexusDeviceRecord? Device { get; init; }
    public NexusRemoteEnrollmentSyncResult? RemoteSync { get; init; }
}

public sealed class NexusRemoteEnrollmentSyncResult
{
    public bool Attempted { get; init; }
    public bool Succeeded { get; init; }
    public string? RemoteStatus { get; init; }
    public string? Message { get; init; }

    public static NexusRemoteEnrollmentSyncResult Skipped() => new() { Attempted = false };

    public static NexusRemoteEnrollmentSyncResult Success(string? status, string? message) =>
        new() { Attempted = true, Succeeded = true, RemoteStatus = status, Message = message };

    public static NexusRemoteEnrollmentSyncResult Failed(string message) =>
        new() { Attempted = true, Succeeded = false, Message = message };
}
