namespace MinicsUI.Helper;

public class HistoryViewer(MonitorHelper monitorHelper)
{

    public bool StartChannelHistory(byte mini8Index, byte channelIndex)
    {
        if (!monitorHelper.Monitors.TryGetValue(monitorHelper.SelectedDisplay, out MonitorInfo? monitorInfo) || monitorInfo is null)
            return false;

        ProcessStartInfo startInfo = new()
        {
            FileName = FilePaths.HistoryExe,
            UseShellExecute = false,
            RedirectStandardOutput = true,
        };


        startInfo.ArgumentList.Add(monitorInfo.StartPixVertical.ToString());
        startInfo.ArgumentList.Add(monitorInfo.StartPixHorizontal.ToString());
        startInfo.ArgumentList.Add(monitorInfo.ResolutionVertical.ToString());
        startInfo.ArgumentList.Add(monitorInfo.ResolutionHorizontal.ToString());
        startInfo.ArgumentList.Add("1");
        startInfo.ArgumentList.Add(mini8Index.ToString());
        startInfo.ArgumentList.Add(channelIndex.ToString());

        try
        {
            Process.Start(startInfo);
            return true;
        }
        catch
        {
            return false;
        }
    }

    public bool StartMultiChannelHistory(byte mini8Index)
    {
        if (!monitorHelper.Monitors.TryGetValue(monitorHelper.SelectedDisplay, out MonitorInfo? monitorInfo) || monitorInfo is null)
            return false;

        ProcessStartInfo startInfo = new()
        {
            FileName = FilePaths.HistoryExe,
            UseShellExecute = false,
            RedirectStandardOutput = true,
        };


        startInfo.ArgumentList.Add(monitorInfo.StartPixVertical.ToString());
        startInfo.ArgumentList.Add(monitorInfo.StartPixHorizontal.ToString());
        startInfo.ArgumentList.Add(monitorInfo.ResolutionVertical.ToString());
        startInfo.ArgumentList.Add(monitorInfo.ResolutionHorizontal.ToString());
        startInfo.ArgumentList.Add("3");
        startInfo.ArgumentList.Add(mini8Index.ToString());
        startInfo.ArgumentList.Add("1");

        try
        {
            Process.Start(startInfo);
            return true;
        }
        catch
        {
            return false;
        }
    }

    public bool StartAlarmHistroy()
    {
        if (!monitorHelper.Monitors.TryGetValue(monitorHelper.SelectedDisplay, out MonitorInfo? monitorInfo) || monitorInfo is null)
            return false;

        ProcessStartInfo startInfo = new()
        {
            FileName = FilePaths.HistoryExe,
            UseShellExecute = false,
            RedirectStandardOutput = true,
        };

        startInfo.ArgumentList.Add(monitorInfo.StartPixVertical.ToString());
        startInfo.ArgumentList.Add(monitorInfo.StartPixHorizontal.ToString());
        startInfo.ArgumentList.Add(monitorInfo.ResolutionVertical.ToString());
        startInfo.ArgumentList.Add(monitorInfo.ResolutionHorizontal.ToString());
        startInfo.ArgumentList.Add("2");

        try
        {
            Process.Start(startInfo);
            return true;
        }
        catch
        {
            return false;
        }
    }
}
