import { PersistentStore } from '../../state/persistent-store.js';
import { resolveAutomationStorePath } from './paths.js';
function defaultSnapshot() {
    return {
        version: 1,
        routes: [],
    };
}
export class AutomationRouteStore {
    store;
    constructor(config = {}) {
        const path = typeof config === 'string'
            ? config
            : config.path ?? resolveAutomationStorePath('automation-routes.json', config.configManager ?? {});
        this.store = new PersistentStore(path);
    }
    async load() {
        const snapshot = await this.store.load();
        if (!snapshot || !Array.isArray(snapshot.routes)) {
            return defaultSnapshot();
        }
        return {
            version: 1,
            routes: snapshot.routes,
        };
    }
    async save(routes) {
        await this.store.persist({
            version: 1,
            routes: [...routes],
        });
    }
}
