"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEventPriority = void 0;
exports.decideOnNewStatusForOrder = decideOnNewStatusForOrder;
const types_1 = require("../order/types");
const types_2 = require("../types");
function decideOnNewStatusForOrder(order) {
    switch (true) {
        case order.refundTimestamp > 0:
            return types_1.OrderStatus.ClaimedRefund;
        case order.claimTimestamp > 0:
            return types_1.OrderStatus.Claimed;
        case order.attestationTimestamp > 0:
            return types_1.OrderStatus.Expired;
        case order.confirmationTimestamp > 0:
            return types_1.OrderStatus.Executed;
        case order.bidTimestamp > 0:
            return types_1.OrderStatus.Expired;
        case order.orderTimestamp > 0:
            return types_1.OrderStatus.Expired;
        default:
            return types_1.OrderStatus.Placed;
    }
}
/**
 * Event priorities – lower number = higher priority.
 * Events omitted automatically fall back as last priority.
 *
 * 0  → Order creation
 * 1  → Bid events
 * 2  → Confirmation
 * 3  → Attestations
 * 4  → Claims
 * 5+ → Refunds & misc
 */
const EVENT_PRIORITY = {
    // Order creation
    [types_2.EventName.OrderCreated]: 0,
    [types_2.EventName.RemoteOrderCreated]: 0,
    [types_2.EventName.EscrowOrderCreated]: 0,
    [types_2.EventName.L3EscrowOrderCreated]: 0,
    // Bids
    [types_2.EventName.BidReceived]: 1,
    // Confirmation
    [types_2.EventName.Confirmation]: 2,
    [types_2.EventName.ConfirmationBatch]: 2,
    // Attestations
    [types_2.EventName.TransferCommitApplied]: 3,
    [types_2.EventName.TransferRevertApplied]: 3,
    [types_2.EventName.RevertOrderApproved]: 3,
    [types_2.EventName.NewOrderAttested]: 3,
    [types_2.EventName.AddPendingAttestationToUnknownOrder]: 3,
    [types_2.EventName.GMPMismatch]: 3,
    [types_2.EventName.NewBatchAttested]: 3,
    // Claims
    [types_2.EventName.Claimed]: 4,
    [types_2.EventName.NonClaimable]: 4,
    [types_2.EventName.NonRefundable]: 4,
    [types_2.EventName.ClaimedBatch]: 4,
    [types_2.EventName.SegmentReceived]: 4,
    [types_2.EventName.InsuranceClaimed]: 4,
    // Refunds/misc
    [types_2.EventName.ClaimedRefund]: 5,
    [types_2.EventName.RevertOrderRevertWithCommitPrevented]: 5,
    [types_2.EventName.InsuranceSet]: 5,
    [types_2.EventName.NewPayloadMemo]: 5,
};
/**
 * Returns numeric priority for an RPC Event SQS message.
 * When eventName attribute is missing/unknown we push the message to the back of the queue.
 */
const getEventPriority = (msg) => {
    const eventName = msg.MessageAttributes?.eventName?.StringValue;
    return eventName ? (EVENT_PRIORITY[eventName] ?? Number.MAX_SAFE_INTEGER) : Number.MAX_SAFE_INTEGER;
};
exports.getEventPriority = getEventPriority;
//# sourceMappingURL=helpers.js.map