package com.cameleer.server.app.alerting.dto;

import com.cameleer.server.app.alerting.eval.EvalResult;

/**
 * Result of a one-shot evaluator run against live data (does not persist any state).
 */
public record TestEvaluateResponse(String resultKind, String detail) {

    public static TestEvaluateResponse from(EvalResult result) {
        if (result instanceof EvalResult.Firing f) {
            return new TestEvaluateResponse("FIRING",
                    "currentValue=" + f.currentValue() + " threshold=" + f.threshold());
        } else if (result instanceof EvalResult.Clear) {
            return new TestEvaluateResponse("CLEAR", null);
        } else if (result instanceof EvalResult.Error e) {
            return new TestEvaluateResponse("ERROR",
                    e.cause() != null ? e.cause().getMessage() : "unknown error");
        } else if (result instanceof EvalResult.Batch b) {
            return new TestEvaluateResponse("BATCH", b.firings().size() + " firing(s)");
        }
        return new TestEvaluateResponse("UNKNOWN", result.getClass().getSimpleName());
    }
}
