using System;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
namespace PSProxmoxVE.Core.Models.Containers;
///
/// Represents a Linux Container (LXC) as returned by the cluster or node container list endpoints.
///
public class PveContainer
{
///
/// The unique container identifier.
///
[JsonPropertyName("vmid")]
[JsonProperty("vmid")]
public int VmId { get; set; }
///
/// The hostname / display name of the container.
///
[JsonPropertyName("name")]
[JsonProperty("name")]
public string? Name { get; set; }
///
/// The current runtime status of the container (e.g., "running", "stopped").
///
[JsonPropertyName("status")]
[JsonProperty("status")]
public string? Status { get; set; }
///
/// The node on which the container resides.
///
[JsonPropertyName("node")]
[JsonProperty("node")]
public string? Node { get; set; }
///
/// The number of CPU cores assigned to the container.
///
[JsonPropertyName("cpus")]
[JsonProperty("cpus")]
public int? CpuCount { get; set; }
///
/// Maximum memory allocated to the container, in bytes.
///
[JsonPropertyName("maxmem")]
[JsonProperty("maxmem")]
public long? MaxMem { get; set; }
///
/// Maximum swap space allocated to the container, in bytes.
///
[JsonPropertyName("maxswap")]
[JsonProperty("maxswap")]
public long? MaxSwap { get; set; }
///
/// Root filesystem disk size allocated to the container, in bytes.
///
[JsonPropertyName("maxdisk")]
[JsonProperty("maxdisk")]
public long? RootFsSize { get; set; }
///
/// The OS template type used for this container (e.g., "debian", "ubuntu").
///
[JsonPropertyName("ostype")]
[JsonProperty("ostype")]
public string? OsType { get; set; }
///
/// Indicates whether the container runs in unprivileged mode (1) or privileged mode (0).
///
[JsonPropertyName("unprivileged")]
[JsonProperty("unprivileged")]
public int? Unprivileged { get; set; }
///
/// The current lock type applied to the container, if any (e.g., "migrate", "backup").
///
[JsonPropertyName("lock")]
[JsonProperty("lock")]
public string? Lock { get; set; }
///
/// Container uptime in seconds.
///
[JsonPropertyName("uptime")]
[JsonProperty("uptime")]
public long? Uptime { get; set; }
///
/// Semicolon-separated list of tags assigned to the container.
///
[JsonPropertyName("tags")]
[JsonProperty("tags")]
public string? Tags { get; set; }
///
public override string ToString()
{
var maxMemMb = MaxMem.HasValue ? $"{MaxMem.Value / 1024 / 1024} MB" : "N/A";
var rootFsGb = RootFsSize.HasValue ? $"{RootFsSize.Value / 1024 / 1024 / 1024} GB" : "N/A";
var uptimeStr = Uptime.HasValue ? TimeSpan.FromSeconds(Uptime.Value).ToString(@"d\.hh\:mm\:ss") : "N/A";
var privStr = Unprivileged is 1 ? "unprivileged" : "privileged";
return $"CT {VmId}: {Name ?? "(unnamed)"} | Node: {Node ?? "N/A"} | "
+ $"Status: {Status ?? "N/A"} | CPUs: {CpuCount?.ToString() ?? "N/A"} | "
+ $"Mem: {maxMemMb} | Disk: {rootFsGb} | {privStr} | Uptime: {uptimeStr}";
}
}