import { v4 as uuid } from 'uuid';
import * as commandStore from '../storage/command-store.js';
export function listCommands(workspaceId) {
    return commandStore.listCommands(workspaceId);
}
export function getCommand(workspaceId, commandId) {
    return commandStore.getCommand(workspaceId, commandId);
}
export function createCommand(workspaceId, input) {
    const now = new Date().toISOString();
    const cmd = {
        id: uuid(),
        name: input.name.trim(),
        command: input.command,
        folder: input.folder,
        cwd: input.cwd,
        shell: input.shell,
        env: input.env,
        autoRestart: input.autoRestart,
        createdAt: now,
        updatedAt: now,
    };
    const commands = commandStore.listCommands(workspaceId);
    commands.push(cmd);
    commandStore.saveCommands(workspaceId, commands);
    return cmd;
}
export function updateCommand(workspaceId, commandId, updates) {
    const commands = commandStore.listCommands(workspaceId);
    const idx = commands.findIndex(c => c.id === commandId);
    if (idx === -1)
        throw new Error('Command not found');
    commands[idx] = {
        ...commands[idx],
        ...updates,
        updatedAt: new Date().toISOString(),
    };
    commandStore.saveCommands(workspaceId, commands);
    return commands[idx];
}
export function deleteCommand(workspaceId, commandId) {
    const commands = commandStore.listCommands(workspaceId);
    const filtered = commands.filter(c => c.id !== commandId);
    if (filtered.length === commands.length)
        throw new Error('Command not found');
    commandStore.saveCommands(workspaceId, filtered);
}
//# sourceMappingURL=command.js.map