import path from 'node:path';
import os from 'node:os';
import { JsonStore } from '../../../database/json-store.js';
function defaultPath() {
    return process.env.ORCHESTRATION_TASKS_PATH ??
        path.join(os.homedir(), '.pixcode', 'orchestration-tasks.json');
}
export class OrchestrationTaskStore {
    store;
    constructor(filePath = defaultPath()) {
        this.store = new JsonStore(filePath, { orchestration_tasks: [] });
    }
    get(id) {
        return this.store.findWhere('orchestration_tasks', (r) => r.id === id) ?? undefined;
    }
    getByA2ATaskId(a2aTaskId) {
        return this.store.findWhere('orchestration_tasks', (r) => r.a2aTaskId === a2aTaskId) ?? undefined;
    }
    getByTaskMasterId(taskmasterId) {
        return this.store.findWhere('orchestration_tasks', (r) => r.taskmasterId === taskmasterId) ?? undefined;
    }
    list(projectId) {
        const tasks = this.store.filterWhere('orchestration_tasks', () => true);
        const sorted = tasks.sort((a, b) => b.createdAt - a.createdAt);
        return projectId ? sorted.filter((task) => task.projectId === projectId) : sorted;
    }
    set(task) {
        const existing = this.store.findWhere('orchestration_tasks', (r) => r.id === task.id);
        if (existing) {
            this.store.updateWhere('orchestration_tasks', (r) => r.id === task.id, task);
        }
        else {
            this.store.insert('orchestration_tasks', task, { autoId: false });
        }
    }
}
//# sourceMappingURL=orchestration-task-store.js.map