"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.settings = void 0;
const connection_js_1 = require("./connection.js");
exports.settings = {
    async get(key) {
        const db = await (0, connection_js_1.getDb)();
        const result = await db.execute({
            sql: 'SELECT value FROM settings WHERE key = ?',
            args: [key],
        });
        if (result.rows.length === 0)
            return null;
        const value = result.rows[0].value;
        try {
            return JSON.parse(value);
        }
        catch {
            return value;
        }
    },
    async set(key, value) {
        const db = await (0, connection_js_1.getDb)();
        const stringValue = typeof value === 'string' ? value : JSON.stringify(value);
        await db.execute({
            sql: 'INSERT OR REPLACE INTO settings (key, value) VALUES (?, ?)',
            args: [key, stringValue],
        });
    },
    async getAll() {
        const db = await (0, connection_js_1.getDb)();
        const result = await db.execute('SELECT key, value FROM settings');
        const out = {};
        for (const row of result.rows) {
            const k = row.key;
            const v = row.value;
            try {
                out[k] = JSON.parse(v);
            }
            catch {
                out[k] = v;
            }
        }
        return out;
    },
};
//# sourceMappingURL=settings.js.map