import { join } from 'node:path';
import { readJsonFile, writeJsonFile, getDataDir } from './json-store.js';
const FILE = () => join(getDataDir(), 'robot-accounts.json');
function read() {
    return readJsonFile(FILE()) ?? { accounts: [] };
}
function write(data) {
    writeJsonFile(FILE(), data);
}
export function listRobotAccounts() {
    return read().accounts;
}
export function getRobotAccount(id) {
    return read().accounts.find((a) => a.id === id);
}
export function createRobotAccount(account) {
    const data = read();
    data.accounts.push(account);
    write(data);
}
export function updateRobotAccount(id, patch) {
    const data = read();
    const idx = data.accounts.findIndex((a) => a.id === id);
    if (idx === -1)
        return null;
    data.accounts[idx] = { ...data.accounts[idx], ...patch, id, updatedAt: new Date().toISOString() };
    write(data);
    return data.accounts[idx];
}
export function deleteRobotAccount(id) {
    const data = read();
    const before = data.accounts.length;
    data.accounts = data.accounts.filter((a) => a.id !== id);
    if (data.accounts.length === before)
        return false;
    write(data);
    return true;
}
//# sourceMappingURL=robot-account-store.js.map