// storage/deploy-config-store.ts — SPEC-478: Persist deploy provider configs per project
import { readJson, writeJson, hashProjectPath, projectDataDir } from './base-store.js';
import { join } from 'node:path';
function pathFor(projectPath) {
    return join(projectDataDir(hashProjectPath(projectPath)), 'deploy-config.json');
}
async function readFile(projectPath) {
    const file = await readJson(pathFor(projectPath), {
        configs: {},
        deployments: [],
    });
    return {
        configs: file.configs,
        deployments: Array.isArray(file.deployments) ? file.deployments : [],
    };
}
export async function saveDeployConfig(projectPath, config) {
    const file = await readFile(projectPath);
    file.configs[config.provider] = config;
    await writeJson(pathFor(projectPath), file);
}
export async function getDeployConfig(projectPath, provider) {
    const file = await readFile(projectPath);
    return file.configs[provider] ?? null;
}
export async function recordDeployment(projectPath, deployment) {
    const file = await readFile(projectPath);
    file.deployments.unshift(deployment);
    file.deployments = file.deployments.slice(0, 50);
    await writeJson(pathFor(projectPath), file);
}
export async function listDeployments(projectPath, provider) {
    const file = await readFile(projectPath);
    if (provider) {
        return file.deployments.filter((d) => d.provider === provider);
    }
    return file.deployments;
}
//# sourceMappingURL=deploy-config-store.js.map