"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LrpWatcherUtils = void 0;
const contracts_1 = require("@codiac.io/codiac-common/contracts");
const message_contracts_1 = require("../message-contracts");
/** Shared logic between LrpWatchers. */
class LrpWatcherUtils {
    static resultFromStatusMessage(status) {
        var _a, _b;
        let result = new contracts_1.Result(false);
        // success
        result.success = Boolean(status.completionCode == message_contracts_1.OperationCompletionCodeEnum.Success);
        // message
        if (status.completionCode != message_contracts_1.OperationCompletionCodeEnum.Success) {
            result.message = status.opCode.concat(" ", (_a = status.completionCode) !== null && _a !== void 0 ? _a : "", ": ", (_b = status.message) !== null && _b !== void 0 ? _b : "").trimEnd();
        }
        else if (status.message) {
            result.message = status.message;
        }
        // error
        if (status.completionCode == message_contracts_1.OperationCompletionCodeEnum.Failed) {
            result.error = new Error(result.message);
        }
        return result;
    }
}
exports.LrpWatcherUtils = LrpWatcherUtils;
/** The value of the `action` field in a SocketAction for status messages. */
LrpWatcherUtils.STATUS_MSG_TYPE = "operationStatus";
//# sourceMappingURL=lrp-watcher-utils.js.map