namespace MiGu.Server.Ota;

/// <summary>MDC 组件文件映射（对齐参考工具 MDCPath.json）。</summary>
public static class OtaPathMap
{
    public static readonly IReadOnlyDictionary<string, string[]> Default = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
    {
        ["M"] = new[] { "Medulla.exe", "plugins\\CartActivator.dll", "plugins\\CartActivator.pdb" },
        ["D"] = new[] { "Detour.exe" },
        ["C"] = new[] { "ClumsyConsole.exe", "FG2305014_C.dll", "FG2305014_C.pdb" }
    };

    public static readonly string[] ComponentKeys =
    {
        "M.exe", "M.dll", "M.pdb", "D.exe", "C.exe", "C.dll", "C.pdb"
    };

    public static string? RelPathFor(string componentKey)
    {
        return componentKey switch
        {
            "M.exe" => "M/Medulla.exe",
            "M.dll" => "M/plugins/CartActivator.dll",
            "M.pdb" => "M/plugins/CartActivator.pdb",
            "D.exe" => "D/Detour.exe",
            "C.exe" => "C/ClumsyConsole.exe",
            "C.dll" => "C/FG2305014_C.dll",
            "C.pdb" => "C/FG2305014_C.pdb",
            _ => null
        };
    }

    public static string? WatchDogUpdatePath(string componentKey) => componentKey switch
    {
        "M.exe" => "updateMedullaExecutable",
        "M.dll" => "updateMedullaDll",
        "M.pdb" => "UpdateMedullaPdb",
        "D.exe" => "updateDetourExecutable",
        "C.exe" => "updateClumsyExecutable",
        "C.dll" => "updateClumsyDll",
        "C.pdb" => "UpdateClumsyPdb",
        _ => null
    };

    public static string AppFolder(string componentKey) => componentKey.StartsWith('M') ? "M"
        : componentKey.StartsWith('D') ? "D" : "C";

    public static string ExtKey(string componentKey)
    {
        var i = componentKey.IndexOf('.');
        return i >= 0 ? componentKey[(i + 1)..] : componentKey;
    }
}
