function asNotificationRecord(value) {
    if (!value || typeof value !== "object" || Array.isArray(value))
        return null;
    return value;
}
function getNotificationStringField(record, key) {
    if (!record)
        return null;
    const value = record[key];
    if (typeof value !== "string")
        return null;
    const trimmed = value.trim();
    return trimmed.length > 0 ? trimmed : null;
}
export function resolveNotificationSubscriptionTarget(notification) {
    const context = asNotificationRecord(notification.context);
    const explicitTargetType = getNotificationStringField(context, "targetType");
    const explicitTargetId = getNotificationStringField(context, "targetId");
    if (explicitTargetType && explicitTargetId) {
        return {
            targetType: explicitTargetType.toLowerCase(),
            targetId: explicitTargetId,
        };
    }
    switch (notification.type) {
        case "item-changed":
        case "feedback": {
            const itemId = getNotificationStringField(context, "itemId");
            return itemId ? { targetType: "item", targetId: itemId } : null;
        }
        case "review-invitation":
        case "review-completed":
        case "review-rejected": {
            const reviewId = getNotificationStringField(context, "reviewId");
            return reviewId ? { targetType: "review", targetId: reviewId } : null;
        }
        case "task-assigned":
        case "task-status-changed": {
            const projectId = getNotificationStringField(context, "projectId");
            return projectId ? { targetType: "project", targetId: projectId } : null;
        }
        default:
            return null;
    }
}
export function resolveNotificationAction(editContext, notification) {
    if (!editContext)
        return null;
    const route = editContext.configuration?.editor?.notificationRoutes?.[notification.type];
    if (!route)
        return null;
    const parsedContext = route.parseContext(notification.context);
    if (!parsedContext)
        return null;
    return {
        open: async () => Boolean(await route.open(editContext, parsedContext)),
    };
}
//# sourceMappingURL=notificationRoutes.js.map