using System; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Unity.Pipeline.Models { /// /// Request model for /api/exec endpoint. /// Contains command name and parameters for remote command execution. /// [Serializable] public class CommandExecutionRequest { /// /// Name of the command to execute. /// Must match a registered [CliCommand] name. /// [JsonProperty("command", Required = Required.Always)] public string Command { get; set; } /// /// Parameters for the command execution. /// Contains key-value pairs matching command parameter names. /// [JsonProperty("parameters")] public JObject Parameters { get; set; } /// /// Optional timeout for command execution in milliseconds. /// Default: 60000 (60 seconds) /// [JsonProperty("timeout")] public int? Timeout { get; set; } /// /// Create a new command execution request. /// public CommandExecutionRequest() { Parameters = new JObject(); } /// /// Create a command execution request with specified command and parameters. /// public CommandExecutionRequest(string command, JObject parameters = null) { Command = command ?? throw new ArgumentNullException(nameof(command)); Parameters = parameters ?? new JObject(); } /// /// Get a parameter value as the specified type. /// Returns the default value if the parameter is not found or cannot be converted. /// public T GetParameter(string name, T defaultValue = default(T)) { if (Parameters == null || !Parameters.ContainsKey(name)) return defaultValue; try { return Parameters[name].ToObject(); } catch { return defaultValue; } } /// /// Check if a parameter exists in the request. /// public bool HasParameter(string name) { return Parameters != null && Parameters.ContainsKey(name); } /// /// Validate the request structure. /// public string Validate() { if (string.IsNullOrWhiteSpace(Command)) return "Command name is required"; if (Timeout.HasValue && Timeout.Value <= 0) return "Timeout must be a positive number"; return null; // No validation errors } } }