namespace LiquidCode.Tester.Worker.Services.Isolate;

/// <summary>
/// Options for running a program in Isolate sandbox
/// </summary>
public class IsolateRunOptions
{
    /// <summary>
    /// Box ID for parallel execution (0-999)
    /// </summary>
    public int BoxId { get; set; }

    /// <summary>
    /// Path to executable to run
    /// </summary>
    public string Executable { get; set; } = string.Empty;

    /// <summary>
    /// Command-line arguments for the executable
    /// </summary>
    public string[]? Arguments { get; set; }

    /// <summary>
    /// CPU time limit in seconds (0 = no limit)
    /// </summary>
    public double TimeLimitSeconds { get; set; }

    /// <summary>
    /// Wall time limit in seconds (0 = no limit)
    /// </summary>
    public double WallTimeLimitSeconds { get; set; }

    /// <summary>
    /// Memory limit in kilobytes (0 = no limit)
    /// </summary>
    public long MemoryLimitKb { get; set; }

    /// <summary>
    /// Stack size limit in kilobytes (0 = default)
    /// </summary>
    public long StackLimitKb { get; set; }

    /// <summary>
    /// Maximum number of processes (0 = no limit, 1 = single process)
    /// </summary>
    public int ProcessLimit { get; set; } = 1;

    /// <summary>
    /// Enable network access (default: false)
    /// </summary>
    public bool EnableNetwork { get; set; } = false;

    /// <summary>
    /// Path to file for stdin redirection
    /// </summary>
    public string? StdinFile { get; set; }

    /// <summary>
    /// Path to file for stdout redirection
    /// </summary>
    public string? StdoutFile { get; set; }

    /// <summary>
    /// Path to file for stderr redirection
    /// </summary>
    public string? StderrFile { get; set; }

    /// <summary>
    /// Working directory inside sandbox
    /// </summary>
    public string? WorkingDirectory { get; set; }

    /// <summary>
    /// Directory bindings (host path -> sandbox path)
    /// </summary>
    public List<DirectoryBinding>? DirectoryBindings { get; set; }

    /// <summary>
    /// Environment variables to set
    /// </summary>
    public Dictionary<string, string>? EnvironmentVariables { get; set; }
}

/// <summary>
/// Directory binding for isolate sandbox
/// </summary>
public class DirectoryBinding
{
    /// <summary>
    /// Path on host system
    /// </summary>
    public string HostPath { get; set; } = string.Empty;

    /// <summary>
    /// Path inside sandbox
    /// </summary>
    public string SandboxPath { get; set; } = string.Empty;

    /// <summary>
    /// Read-only binding (default: true)
    /// </summary>
    public bool ReadOnly { get; set; } = true;
}
