namespace LiquidCode.Tester.Worker.Services.Isolate;

/// <summary>
/// Result of program execution in Isolate sandbox
/// </summary>
public class IsolateExecutionResult
{
    /// <summary>
    /// Standard output from the program
    /// </summary>
    public string Output { get; set; } = string.Empty;

    /// <summary>
    /// Standard error output from the program
    /// </summary>
    public string ErrorOutput { get; set; } = string.Empty;

    /// <summary>
    /// CPU time used in seconds
    /// </summary>
    public double CpuTimeSeconds { get; set; }

    /// <summary>
    /// Wall (real) time used in seconds
    /// </summary>
    public double WallTimeSeconds { get; set; }

    /// <summary>
    /// Memory used in kilobytes (from cgroups)
    /// </summary>
    public long MemoryUsedKb { get; set; }

    /// <summary>
    /// Maximum resident set size in kilobytes
    /// </summary>
    public long MaxRssKb { get; set; }

    /// <summary>
    /// Exit code of the program
    /// </summary>
    public int ExitCode { get; set; }

    /// <summary>
    /// Exit signal if program was killed by signal
    /// </summary>
    public int? ExitSignal { get; set; }

    /// <summary>
    /// Status code from isolate (RE/SG/TO/XX/OK)
    /// </summary>
    public string Status { get; set; } = string.Empty;

    /// <summary>
    /// Additional message from isolate
    /// </summary>
    public string Message { get; set; } = string.Empty;

    /// <summary>
    /// Whether the program was killed
    /// </summary>
    public bool WasKilled { get; set; }

    /// <summary>
    /// Whether time limit was exceeded
    /// </summary>
    public bool TimeLimitExceeded { get; set; }

    /// <summary>
    /// Whether memory limit was exceeded
    /// </summary>
    public bool MemoryLimitExceeded { get; set; }

    /// <summary>
    /// Whether program had runtime error
    /// </summary>
    public bool RuntimeError { get; set; }

    /// <summary>
    /// Whether process was killed by cgroup OOM killer
    /// </summary>
    public bool CgroupOomKilled { get; set; }

    /// <summary>
    /// Number of voluntary context switches
    /// </summary>
    public int VoluntaryContextSwitches { get; set; }

    /// <summary>
    /// Number of forced context switches
    /// </summary>
    public int ForcedContextSwitches { get; set; }

    /// <summary>
    /// Whether execution was successful (no errors, no limits exceeded)
    /// </summary>
    public bool Success => ExitCode == 0 && !TimeLimitExceeded && !MemoryLimitExceeded && !RuntimeError;
}
