namespace DodoSSH.Client.Terminal;

/// <summary>One file the renderer needs.</summary>
/// <param name="ContentType">MIME type, including a charset for text.</param>
/// <param name="Content">The bytes to serve.</param>
public sealed record TerminalAsset(string ContentType, byte[] Content);

/// <summary>
/// Supplies the renderer's HTML, JavaScript and CSS.
/// </summary>
/// <remarks>
/// An abstraction so the data plane does not depend on Avalonia's resource system, which keeps the
/// whole transport testable with in-memory assets. The application implements this over
/// <c>AvaloniaResource</c>; tests hand over a dictionary.
/// </remarks>
public interface ITerminalAssetProvider
{
    /// <summary>
    /// Returns the asset for a request path, or null if there is none.
    /// </summary>
    /// <param name="path">Absolute request path, beginning with a slash.</param>
    TerminalAsset? Find(string path);
}

/// <summary>Assets held in a dictionary.</summary>
public sealed class InMemoryTerminalAssetProvider(IReadOnlyDictionary<string, TerminalAsset> assets)
    : ITerminalAssetProvider
{
    /// <inheritdoc />
    public TerminalAsset? Find(string path) => assets.GetValueOrDefault(path);
}
