// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.


using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using Microsoft.DotNet.Watcher.Internal;

namespace Microsoft.DotNet.Watcher
{
    internal sealed class ProcessSpec
    {
        public string? Executable { get; set; }
        public string? WorkingDirectory { get; set; }
        public Dictionary<string, string> EnvironmentVariables { get; } = new();
        public IReadOnlyList<string>? Arguments { get; set; }
        public string? EscapedArguments { get; set; }
        public OutputCapture? OutputCapture { get; set; }
        public DataReceivedEventHandler? OnOutput { get; set; }
        public CancellationToken CancelOutputCapture { get; set; }

        [MemberNotNullWhen(true, nameof(OutputCapture))]
        public bool IsOutputCaptured => OutputCapture != null;

        public string? ShortDisplayName()
            => Path.GetFileNameWithoutExtension(Executable);

        public string GetArgumentsDisplay()
            => EscapedArguments ?? CommandLineUtilities.JoinArguments(Arguments ?? []);
    }
}
