package org.ghidra.bridge.runtime;

import java.util.LinkedHashMap;
import java.util.Map;

import ghidra.pyghidra.PyGhidraTaskMonitor;
import ghidra.util.task.TaskMonitor;

public final class TaskMonitors {
    private TaskMonitors() {
    }

    public static TaskMonitor create(int timeoutSeconds) {
        if (timeoutSeconds < 0) {
            return TaskMonitor.DUMMY;
        }
        return new PyGhidraTaskMonitor(Integer.valueOf(timeoutSeconds), null);
    }

    public static Map<String, Object> report(TaskMonitor monitor, int timeoutSeconds) {
        Map<String, Object> report = new LinkedHashMap<>();
        report.put("timeout_seconds", timeoutSeconds < 0 ? null : Integer.valueOf(timeoutSeconds));
        report.put("cancelled", monitor.isCancelled());
        report.put("message", monitor.getMessage() == null ? "" : monitor.getMessage());
        report.put("progress", monitor.getProgress());
        report.put("maximum", monitor.getMaximum());
        return report;
    }
}
