export async function loadWorkspaceAutomationsCount({ backend, workspace, }) {
    const result = await backend.workspace(workspace).automations().getAutomationsQuery().withSize(1).query();
    return result.totalCount ?? 0;
}
export function loadDashboardUserAutomations(ctx, dashboardId, userId, filterByUser, externalRecipient) {
    const { backend, workspace } = ctx;
    let dashboardQuery = backend
        .workspace(workspace)
        .automations()
        .getAutomationsQuery()
        .withSorting(["title,asc", "createdAt,asc"])
        .withDashboard(dashboardId);
    // External recipients from context are prioritized to signed-in user
    if (externalRecipient) {
        dashboardQuery = dashboardQuery.withExternalRecipient(externalRecipient);
    }
    else if (filterByUser) {
        dashboardQuery = dashboardQuery.withUser(userId);
    }
    return dashboardQuery.queryAll();
}
