import * as workspaceService from '../workspace.js';
export function shouldNotify(workspaceId, event) {
    const settings = workspaceService.getById(workspaceId)?.notificationSettings;
    return Boolean(settings?.enabled && settings.events?.includes(event));
}
export function isIssueStartStatus(status) {
    return status === 'planned' || status === 'in_progress';
}
export function isTaskDoneStatus(status) {
    return status === 'done' || status === 'failed' || status === 'cancelled';
}
export function persistServiceRunning(workspaceId, serviceRunning) {
    const workspace = workspaceService.getById(workspaceId);
    const settings = workspace?.notificationSettings;
    if (!workspace || !settings || settings.serviceRunning === serviceRunning)
        return;
    workspaceService.update(workspaceId, {
        notificationSettings: {
            ...settings,
            serviceRunning,
        },
    });
}
export function persistLarkChatIds(workspaceId, chatIds) {
    const workspace = workspaceService.getById(workspaceId);
    const settings = workspace?.notificationSettings;
    if (!workspace || !settings)
        return;
    workspaceService.update(workspaceId, {
        notificationSettings: {
            ...settings,
            lark: {
                ...settings.lark,
                chatIds: [...new Set(chatIds)],
            },
        },
    });
}
export function persistWeChatUserIds(workspaceId, userIds) {
    const workspace = workspaceService.getById(workspaceId);
    const settings = workspace?.notificationSettings;
    if (!workspace || !settings)
        return;
    workspaceService.update(workspaceId, {
        notificationSettings: {
            ...settings,
            wechat: {
                ...settings.wechat,
                userIds: [...new Set(userIds)],
            },
        },
    });
}
export function persistWeChatGetUpdatesBuf(workspaceId, getUpdatesBuf) {
    const workspace = workspaceService.getById(workspaceId);
    const settings = workspace?.notificationSettings;
    if (!workspace || !settings)
        return;
    workspaceService.update(workspaceId, {
        notificationSettings: {
            ...settings,
            wechat: {
                ...settings.wechat,
                getUpdatesBuf,
            },
        },
    });
}
export function getBotSettings(workspaceId) {
    const settings = workspaceService.getById(workspaceId)?.notificationSettings;
    return { markdown: settings?.botMarkdown !== false };
}
export function persistBotMarkdown(workspaceId, markdown) {
    const workspace = workspaceService.getById(workspaceId);
    const settings = workspace?.notificationSettings;
    if (!workspace || !settings)
        return;
    settings.botMarkdown = markdown;
    workspaceService.update(workspaceId, { notificationSettings: { ...settings } });
}
export function sleep(ms) {
    return new Promise((resolve) => setTimeout(resolve, ms));
}
//# sourceMappingURL=helpers.js.map